[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10 namespace Zend\Code\Generator; 11 12 use function is_array; 13 use function is_string; 14 use function sprintf; 15 16 abstract class AbstractMemberGenerator extends AbstractGenerator 17 { 18 /**#@+ 19 * @const int Flags for construction usage 20 */ 21 const FLAG_ABSTRACT = 0x01; 22 const FLAG_FINAL = 0x02; 23 const FLAG_STATIC = 0x04; 24 const FLAG_INTERFACE = 0x08; 25 const FLAG_PUBLIC = 0x10; 26 const FLAG_PROTECTED = 0x20; 27 const FLAG_PRIVATE = 0x40; 28 /**#@-*/ 29 30 /**#@+ 31 * @param const string 32 */ 33 const VISIBILITY_PUBLIC = 'public'; 34 const VISIBILITY_PROTECTED = 'protected'; 35 const VISIBILITY_PRIVATE = 'private'; 36 /**#@-*/ 37 38 /** 39 * @var DocBlockGenerator|null 40 */ 41 protected $docBlock; 42 43 /** 44 * @var string 45 */ 46 protected $name; 47 48 /** 49 * @var int 50 */ 51 protected $flags = self::FLAG_PUBLIC; 52 53 /** 54 * @param int|array $flags 55 * @return AbstractMemberGenerator 56 */ 57 public function setFlags($flags) 58 { 59 if (is_array($flags)) { 60 $flagsArray = $flags; 61 $flags = 0x00; 62 foreach ($flagsArray as $flag) { 63 $flags |= $flag; 64 } 65 } 66 // check that visibility is one of three 67 $this->flags = $flags; 68 69 return $this; 70 } 71 72 /** 73 * @param int $flag 74 * @return AbstractMemberGenerator 75 */ 76 public function addFlag($flag) 77 { 78 $this->setFlags($this->flags | $flag); 79 return $this; 80 } 81 82 /** 83 * @param int $flag 84 * @return AbstractMemberGenerator 85 */ 86 public function removeFlag($flag) 87 { 88 $this->setFlags($this->flags & ~$flag); 89 return $this; 90 } 91 92 /** 93 * @param bool $isAbstract 94 * @return AbstractMemberGenerator 95 */ 96 public function setAbstract($isAbstract) 97 { 98 return $isAbstract ? $this->addFlag(self::FLAG_ABSTRACT) : $this->removeFlag(self::FLAG_ABSTRACT); 99 } 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |