Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
PrototypeClassFactory.php
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-2016 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 use function str_replace;
015
016 /**
017 * This is a factory for classes which are identified by name.
018 *
019 * All classes that this factory can supply need to
020 * be registered before (prototypes). This prototypes need to implement
021 * an interface which ensures every prototype has a name.
022 *
023 * If the factory can not supply the class someone is asking for
024 * it tries to fallback on a generic default prototype, which would
025 * have need to be set before.
026 */
027 class PrototypeClassFactory
028 {
029 /**
030 * @var array
031 */
032 protected $prototypes = [];
033
034 /**
035 * @var PrototypeGenericInterface
036 */
037 protected $genericPrototype;
038
039 /**
040 * @param PrototypeInterface[] $prototypes
041 * @param PrototypeGenericInterface $genericPrototype
042 */
043 public function __construct($prototypes = [], PrototypeGenericInterface $genericPrototype = null)
044 {
045 foreach ((array) $prototypes as $prototype) {
046 $this->addPrototype($prototype);
047 }
048
049 if ($genericPrototype) {
050 $this->setGenericPrototype($genericPrototype);
051 }
052 }
053
054 /**
055 * @param PrototypeInterface $prototype
056 * @throws Exception\InvalidArgumentException
057 */
058 public function addPrototype(PrototypeInterface $prototype)
059 {
060 $prototypeName = $this->normalizeName($prototype->getName());
061
062 if (isset($this->prototypes[$prototypeName])) {
063 throw new Exception\InvalidArgumentException('A prototype with this name already exists in this manager');
064 }
065
066 $this->prototypes[$prototypeName] = $prototype;
067 }
068
069 /**
070 * @param PrototypeGenericInterface $prototype
071 * @throws Exception\InvalidArgumentException
072 */
073 public function setGenericPrototype(PrototypeGenericInterface $prototype)
074 {
075 if (isset($this->genericPrototype)) {
076 throw new Exception\InvalidArgumentException('A default prototype is already set');
077 }
078
079 $this->genericPrototype = $prototype;
080 }
081
082 /**
083 * @param string $name
084 * @return string
085 */
086 protected function normalizeName($name)
087 {
088 return str_replace(['-', '_'], '', $name);
089 }
090
091 /**
092 * @param string $name
093 * @return bool
094 */
095 public function hasPrototype($name)
096 {
097 $name = $this->normalizeName($name);
098 return isset($this->prototypes[$name]);
099 }
100
101 /**
102 * @param string $prototypeName
103 * @return PrototypeInterface
104 * @throws Exception\RuntimeException
105 */
106 public function getClonedPrototype($prototypeName)
107 {
108 $prototypeName = $this->normalizeName($prototypeName);
109
110 if (! $this->hasPrototype($prototypeName) && ! isset($this->genericPrototype)) {
111 throw new Exception\RuntimeException('This tag name is not supported by this tag manager');
112 }
113
114 if (! $this->hasPrototype($prototypeName)) {
115 $newPrototype = clone $this->genericPrototype;
116 $newPrototype->setName($prototypeName);
117 } else {
118 $newPrototype = clone $this->prototypes[$prototypeName];
119 }
120
121 return $newPrototype;
122 }
123 }
124