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 |
AbstractMemberGenerator.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\Generator;
011
012 use function is_array;
013 use function is_string;
014 use function sprintf;
015
016 abstract class AbstractMemberGenerator extends AbstractGenerator
017 {
018 /**#@+
019 * @const int Flags for construction usage
020 */
021 const FLAG_ABSTRACT = 0x01;
022 const FLAG_FINAL = 0x02;
023 const FLAG_STATIC = 0x04;
024 const FLAG_INTERFACE = 0x08;
025 const FLAG_PUBLIC = 0x10;
026 const FLAG_PROTECTED = 0x20;
027 const FLAG_PRIVATE = 0x40;
028 /**#@-*/
029
030 /**#@+
031 * @param const string
032 */
033 const VISIBILITY_PUBLIC = 'public';
034 const VISIBILITY_PROTECTED = 'protected';
035 const VISIBILITY_PRIVATE = 'private';
036 /**#@-*/
037
038 /**
039 * @var DocBlockGenerator|null
040 */
041 protected $docBlock;
042
043 /**
044 * @var string
045 */
046 protected $name;
047
048 /**
049 * @var int
050 */
051 protected $flags = self::FLAG_PUBLIC;
052
053 /**
054 * @param int|array $flags
055 * @return AbstractMemberGenerator
056 */
057 public function setFlags($flags)
058 {
059 if (is_array($flags)) {
060 $flagsArray = $flags;
061 $flags = 0x00;
062 foreach ($flagsArray as $flag) {
063 $flags |= $flag;
064 }
065 }
066 // check that visibility is one of three
067 $this->flags = $flags;
068
069 return $this;
070 }
071
072 /**
073 * @param int $flag
074 * @return AbstractMemberGenerator
075 */
076 public function addFlag($flag)
077 {
078 $this->setFlags($this->flags | $flag);
079 return $this;
080 }
081
082 /**
083 * @param int $flag
084 * @return AbstractMemberGenerator
085 */
086 public function removeFlag($flag)
087 {
088 $this->setFlags($this->flags & ~$flag);
089 return $this;
090 }
091
092 /**
093 * @param bool $isAbstract
094 * @return AbstractMemberGenerator
095 */
096 public function setAbstract($isAbstract)
097 {
098 return $isAbstract ? $this->addFlag(self::FLAG_ABSTRACT) : $this->removeFlag(self::FLAG_ABSTRACT);
099 }
100
101 /**
102 * @return bool
103 */
104 public function isAbstract()
105 {
106 return (bool) ($this->flags & self::FLAG_ABSTRACT);
107 }
108
109 /**
110 * @param bool $isInterface
111 * @return AbstractMemberGenerator
112 */
113 public function setInterface($isInterface)
114 {
115 return $isInterface ? $this->addFlag(self::FLAG_INTERFACE) : $this->removeFlag(self::FLAG_INTERFACE);
116 }
117
118 /**
119 * @return bool
120 */
121 public function isInterface()
122 {
123 return (bool) ($this->flags & self::FLAG_INTERFACE);
124 }
125
126 /**
127 * @param bool $isFinal
128 * @return AbstractMemberGenerator
129 */
130 public function setFinal($isFinal)
131 {
132 return $isFinal ? $this->addFlag(self::FLAG_FINAL) : $this->removeFlag(self::FLAG_FINAL);
133 }
134
135 /**
136 * @return bool
137 */
138 public function isFinal()
139 {
140 return (bool) ($this->flags & self::FLAG_FINAL);
141 }
142
143 /**
144 * @param bool $isStatic
145 * @return AbstractMemberGenerator
146 */
147 public function setStatic($isStatic)
148 {
149 return $isStatic ? $this->addFlag(self::FLAG_STATIC) : $this->removeFlag(self::FLAG_STATIC);
150 }
151
152 /**
153 * @return bool
154 */
155 public function isStatic()
156 {
157 return (bool) ($this->flags & self::FLAG_STATIC); // is FLAG_STATIC in flags
158 }
159
160 /**
161 * @param string $visibility
162 * @return AbstractMemberGenerator
163 */
164 public function setVisibility($visibility)
165 {
166 switch ($visibility) {
167 case self::VISIBILITY_PUBLIC:
168 $this->removeFlag(self::FLAG_PRIVATE | self::FLAG_PROTECTED); // remove both
169 $this->addFlag(self::FLAG_PUBLIC);
170 break;
171 case self::VISIBILITY_PROTECTED:
172 $this->removeFlag(self::FLAG_PUBLIC | self::FLAG_PRIVATE); // remove both
173 $this->addFlag(self::FLAG_PROTECTED);
174 break;
175 case self::VISIBILITY_PRIVATE:
176 $this->removeFlag(self::FLAG_PUBLIC | self::FLAG_PROTECTED); // remove both
177 $this->addFlag(self::FLAG_PRIVATE);
178 break;
179 }
180
181 return $this;
182 }
183
184 /**
185 * @return string
186 */
187 public function getVisibility()
188 {
189 switch (true) {
190 case $this->flags & self::FLAG_PROTECTED:
191 return self::VISIBILITY_PROTECTED;
192 case $this->flags & self::FLAG_PRIVATE:
193 return self::VISIBILITY_PRIVATE;
194 default:
195 return self::VISIBILITY_PUBLIC;
196 }
197 }
198
199 /**
200 * @param string $name
201 * @return AbstractMemberGenerator
202 */
203 public function setName($name)
204 {
205 $this->name = (string) $name;
206 return $this;
207 }
208
209 /**
210 * @return string
211 */
212 public function getName()
213 {
214 return $this->name;
215 }
216
217 /**
218 * @param DocBlockGenerator|string $docBlock
219 * @throws Exception\InvalidArgumentException
220 * @return AbstractMemberGenerator
221 */
222 public function setDocBlock($docBlock)
223 {
224 if (is_string($docBlock)) {
225 $docBlock = new DocBlockGenerator($docBlock);
226 } elseif (! $docBlock instanceof DocBlockGenerator) {
227 throw new Exception\InvalidArgumentException(sprintf(
228 '%s is expecting either a string, array or an instance of %s\DocBlockGenerator',
229 __METHOD__,
230 __NAMESPACE__
231 ));
232 }
233
234 $this->docBlock = $docBlock;
235
236 return $this;
237 }
238
239 public function removeDocBlock(): void
240 {
241 $this->docBlock = null;
242 }
243
244 /**
245 * @return DocBlockGenerator|null
246 */
247 public function getDocBlock()
248 {
249 return $this->docBlock;
250 }
251 }
252