[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/zendframework/zend-code/src/Generator/ -> AbstractMemberGenerator.php (source)

   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-2015 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  abstract class AbstractMemberGenerator extends AbstractGenerator
  13  {
  14      /**#@+
  15       * @const int Flags for construction usage
  16       */
  17      const FLAG_ABSTRACT  = 0x01;
  18      const FLAG_FINAL     = 0x02;
  19      const FLAG_STATIC    = 0x04;
  20      const FLAG_PUBLIC    = 0x10;
  21      const FLAG_PROTECTED = 0x20;
  22      const FLAG_PRIVATE   = 0x40;
  23      /**#@-*/
  24  
  25      /**#@+
  26       * @param const string
  27       */
  28      const VISIBILITY_PUBLIC    = 'public';
  29      const VISIBILITY_PROTECTED = 'protected';
  30      const VISIBILITY_PRIVATE   = 'private';
  31      /**#@-*/
  32  
  33      /**
  34       * @var DocBlockGenerator
  35       */
  36      protected $docBlock = null;
  37  
  38      /**
  39       * @var string
  40       */
  41      protected $name = null;
  42  
  43      /**
  44       * @var int
  45       */
  46      protected $flags = self::FLAG_PUBLIC;
  47  
  48      /**
  49       * @param  int|array $flags
  50       * @return AbstractMemberGenerator
  51       */
  52      public function setFlags($flags)
  53      {
  54          if (is_array($flags)) {
  55              $flagsArray = $flags;
  56              $flags      = 0x00;
  57              foreach ($flagsArray as $flag) {
  58                  $flags |= $flag;
  59              }
  60          }
  61          // check that visibility is one of three
  62          $this->flags = $flags;
  63  
  64          return $this;
  65      }
  66  
  67      /**
  68       * @param  int $flag
  69       * @return AbstractMemberGenerator
  70       */
  71      public function addFlag($flag)
  72      {
  73          $this->setFlags($this->flags | $flag);
  74          return $this;
  75      }
  76  
  77      /**
  78       * @param  int $flag
  79       * @return AbstractMemberGenerator
  80       */
  81      public function removeFlag($flag)
  82      {
  83          $this->setFlags($this->flags & ~$flag);
  84          return $this;
  85      }
  86  
  87      /**
  88       * @param  bool $isAbstract
  89       * @return AbstractMemberGenerator
  90       */
  91      public function setAbstract($isAbstract)
  92      {
  93          return (($isAbstract) ? $this->addFlag(self::FLAG_ABSTRACT) : $this->removeFlag(self::FLAG_ABSTRACT));
  94      }
  95  
  96      /**
  97       * @return bool
  98       */
  99      public function isAbstract()
 100      {
 101          return (bool) ($this->flags & self::FLAG_ABSTRACT);
 102      }
 103  
 104      /**
 105       * @param  bool $isFinal
 106       * @return AbstractMemberGenerator
 107       */
 108      public function setFinal($isFinal)
 109      {
 110          return (($isFinal) ? $this->addFlag(self::FLAG_FINAL) : $this->removeFlag(self::FLAG_FINAL));
 111      }
 112  
 113      /**
 114       * @return bool
 115       */
 116      public function isFinal()
 117      {
 118          return (bool) ($this->flags & self::FLAG_FINAL);
 119      }
 120  
 121      /**
 122       * @param  bool $isStatic
 123       * @return AbstractMemberGenerator
 124       */
 125      public function setStatic($isStatic)
 126      {
 127          return (($isStatic) ? $this->addFlag(self::FLAG_STATIC) : $this->removeFlag(self::FLAG_STATIC));
 128      }
 129  
 130      /**
 131       * @return bool
 132       */
 133      public function isStatic()
 134      {
 135          return (bool) ($this->flags & self::FLAG_STATIC); // is FLAG_STATIC in flags
 136      }
 137  
 138      /**
 139       * @param  string $visibility
 140       * @return AbstractMemberGenerator
 141       */
 142      public function setVisibility($visibility)
 143      {
 144          switch ($visibility) {
 145              case self::VISIBILITY_PUBLIC:
 146                  $this->removeFlag(self::FLAG_PRIVATE | self::FLAG_PROTECTED); // remove both
 147                  $this->addFlag(self::FLAG_PUBLIC);
 148                  break;
 149              case self::VISIBILITY_PROTECTED:
 150                  $this->removeFlag(self::FLAG_PUBLIC | self::FLAG_PRIVATE); // remove both
 151                  $this->addFlag(self::FLAG_PROTECTED);
 152                  break;
 153              case self::VISIBILITY_PRIVATE:
 154                  $this->removeFlag(self::FLAG_PUBLIC | self::FLAG_PROTECTED); // remove both
 155                  $this->addFlag(self::FLAG_PRIVATE);
 156                  break;
 157          }
 158  
 159          return $this;
 160      }
 161  
 162      /**
 163       * @return string
 164       */
 165      public function getVisibility()
 166      {
 167          switch (true) {
 168              case ($this->flags & self::FLAG_PROTECTED):
 169                  return self::VISIBILITY_PROTECTED;
 170              case ($this->flags & self::FLAG_PRIVATE):
 171                  return self::VISIBILITY_PRIVATE;
 172              default:
 173                  return self::VISIBILITY_PUBLIC;
 174          }
 175      }
 176  
 177      /**
 178       * @param  string $name
 179       * @return AbstractMemberGenerator
 180       */
 181      public function setName($name)
 182      {
 183          $this->name = (string) $name;
 184          return $this;
 185      }
 186  
 187      /**
 188       * @return string
 189       */
 190      public function getName()
 191      {
 192          return $this->name;
 193      }
 194  
 195      /**
 196       * @param  DocBlockGenerator|string $docBlock
 197       * @throws Exception\InvalidArgumentException
 198       * @return AbstractMemberGenerator
 199       */
 200      public function setDocBlock($docBlock)
 201      {
 202          if (is_string($docBlock)) {
 203              $docBlock = new DocBlockGenerator($docBlock);
 204          } elseif (!$docBlock instanceof DocBlockGenerator) {
 205              throw new Exception\InvalidArgumentException(sprintf(
 206                  '%s is expecting either a string, array or an instance of %s\DocBlockGenerator',
 207                  __METHOD__,
 208                  __NAMESPACE__
 209              ));
 210          }
 211  
 212          $this->docBlock = $docBlock;
 213  
 214          return $this;
 215      }
 216  
 217      /**
 218       * @return DocBlockGenerator
 219       */
 220      public function getDocBlock()
 221      {
 222          return $this->docBlock;
 223      }
 224  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1