Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

PrototypeClassFactory.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 3.42 KiB


001  <?php
002  /**
003   * Zend Framework (http://framework.zend.com/)
004   *
005   * @link      http://github.com/zendframework/zf2 for the canonical source repository
006   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
007   * @license   http://framework.zend.com/license/new-bsd New BSD License
008   */
009   
010  namespace Zend\Code\Generic\Prototype;
011   
012  use Zend\Code\Reflection\Exception;
013   
014  /**
015   * This is a factory for classes which are identified by name.
016   *
017   * All classes that this factory can supply need to
018   * be registered before (prototypes). This prototypes need to implement
019   * an interface which ensures every prototype has a name.
020   *
021   * If the factory can not supply the class someone is asking for
022   * it tries to fallback on a generic default prototype, which would
023   * have need to be set before.
024   */
025  class PrototypeClassFactory
026  {
027      /**
028       * @var array
029       */
030      protected $prototypes = array();
031   
032      /**
033       * @var PrototypeGenericInterface
034       */
035      protected $genericPrototype = null;
036   
037      /**
038       * @param PrototypeInterface[] $prototypes
039       * @param PrototypeGenericInterface $genericPrototype
040       */
041      public function __construct($prototypes = array(), PrototypeGenericInterface $genericPrototype = null)
042      {
043          foreach ((array)$prototypes as $prototype) {
044              $this->addPrototype($prototype);
045          }
046   
047          if ($genericPrototype) {
048              $this->setGenericPrototype($genericPrototype);
049          }
050      }
051   
052      /**
053       * @param PrototypeInterface $prototype
054       * @throws Exception\InvalidArgumentException
055       */
056      public function addPrototype(PrototypeInterface $prototype)
057      {
058          $prototypeName = $this->normalizeName($prototype->getName());
059   
060          if (isset($this->prototypes[$prototypeName])) {
061              throw new Exception\InvalidArgumentException('A prototype with this name already exists in this manager');
062          }
063   
064          $this->prototypes[$prototypeName] = $prototype;
065      }
066   
067      /**
068       * @param PrototypeGenericInterface $prototype
069       * @throws Exception\InvalidArgumentException
070       */
071      public function setGenericPrototype(PrototypeGenericInterface $prototype)
072      {
073          if (isset($this->genericPrototype)) {
074              throw new Exception\InvalidArgumentException('A default prototype is already set');
075          }
076   
077          $this->genericPrototype = $prototype;
078      }
079   
080      /**
081       * @param string $name
082       * @return string
083       */
084      protected function normalizeName($name)
085      {
086          return str_replace(array('-', '_'), '', $name);
087      }
088   
089      /**
090       * @param string $name
091       * @return bool
092       */
093      public function hasPrototype($name)
094      {
095          $name = $this->normalizeName($name);
096          return isset($this->prototypes[$name]);
097      }
098   
099      /**
100       * @param  string $prototypeName
101       * @return PrototypeInterface
102       * @throws Exception\RuntimeException
103       */
104      public function getClonedPrototype($prototypeName)
105      {
106          $prototypeName = $this->normalizeName($prototypeName);
107   
108          if (!$this->hasPrototype($prototypeName) && !isset($this->genericPrototype)) {
109              throw new Exception\RuntimeException('This tag name is not supported by this tag manager');
110          }
111   
112          if (!$this->hasPrototype($prototypeName)) {
113              $newPrototype = clone $this->genericPrototype;
114              $newPrototype->setName($prototypeName);
115          } else {
116              $newPrototype = clone $this->prototypes[$prototypeName];
117          }
118   
119          return $newPrototype;
120      }
121  }
122