[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

/vendor/zendframework/zend-code/src/Reflection/ -> ClassReflection.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-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\Reflection;
  11  
  12  use ReflectionClass;
  13  use Zend\Code\Annotation\AnnotationCollection;
  14  use Zend\Code\Annotation\AnnotationManager;
  15  use Zend\Code\Scanner\AnnotationScanner;
  16  use Zend\Code\Scanner\FileScanner;
  17  
  18  use function array_shift;
  19  use function array_slice;
  20  use function array_unshift;
  21  use function file;
  22  use function file_exists;
  23  use function implode;
  24  use function strstr;
  25  
  26  class ClassReflection extends ReflectionClass implements ReflectionInterface
  27  {
  28      /**
  29       * @var AnnotationScanner
  30       */
  31      protected $annotations;
  32  
  33      /**
  34       * @var DocBlockReflection
  35       */
  36      protected $docBlock;
  37  
  38      /**
  39       * Return the reflection file of the declaring file.
  40       *
  41       * @return FileReflection
  42       */
  43      public function getDeclaringFile()
  44      {
  45          $instance = new FileReflection($this->getFileName());
  46  
  47          return $instance;
  48      }
  49  
  50      /**
  51       * Return the classes DocBlock reflection object
  52       *
  53       * @return DocBlockReflection|false
  54       * @throws Exception\ExceptionInterface for missing DocBock or invalid reflection class
  55       */
  56      public function getDocBlock()
  57      {
  58          if (isset($this->docBlock)) {
  59              return $this->docBlock;
  60          }
  61  
  62          if ('' == $this->getDocComment()) {
  63              return false;
  64          }
  65  
  66          $this->docBlock = new DocBlockReflection($this);
  67  
  68          return $this->docBlock;
  69      }
  70  
  71      /**
  72       * @param  AnnotationManager $annotationManager
  73       * @return AnnotationCollection|false
  74       */
  75      public function getAnnotations(AnnotationManager $annotationManager)
  76      {
  77          $docComment = $this->getDocComment();
  78  
  79          if ($docComment == '') {
  80              return false;
  81          }
  82  
  83          if ($this->annotations) {
  84              return $this->annotations;
  85          }
  86  
  87          $fileScanner       = $this->createFileScanner($this->getFileName());
  88          $nameInformation   = $fileScanner->getClassNameInformation($this->getName());
  89  
  90          if (! $nameInformation) {
  91              return false;
  92          }
  93  
  94          $this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation);
  95  
  96          return $this->annotations;
  97      }
  98  
  99      /**
 100       * Return the start line of the class
 101       *
 102       * @param  bool $includeDocComment
 103       * @return int
 104       */
 105      public function getStartLine($includeDocComment = false)
 106      {
 107          if ($includeDocComment && $this->getDocComment() != '') {
 108              return $this->getDocBlock()->getStartLine();
 109          }
 110  
 111          return parent::getStartLine();
 112      }
 113  
 114      /**
 115       * Return the contents of the class
 116       *
 117       * @param  bool $includeDocBlock
 118       * @return string
 119       */
 120      public function getContents($includeDocBlock = true)
 121      {
 122          $fileName = $this->getFileName();
 123  
 124          if (false === $fileName || ! file_exists($fileName)) {
 125              return '';
 126          }
 127  
 128          $filelines = file($fileName);
 129          $startnum  = $this->getStartLine($includeDocBlock);
 130          $endnum    = $this->getEndLine() - $this->getStartLine();
 131  
 132          // Ensure we get between the open and close braces
 133          $lines = array_slice($filelines, $startnum, $endnum);
 134          array_unshift($lines, $filelines[$startnum - 1]);
 135  
 136          return strstr(implode('', $lines), '{');
 137      }
 138  
 139      /**
 140       * Get all reflection objects of implemented interfaces
 141       *
 142       * @return ClassReflection[]
 143       */
 144      public function getInterfaces()
 145      {
 146          $phpReflections  = parent::getInterfaces();
 147          $zendReflections = [];
 148          while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
 149              $instance          = new ClassReflection($phpReflection->getName());
 150              $zendReflections[] = $instance;
 151              unset($phpReflection);
 152          }
 153          unset($phpReflections);
 154  
 155          return $zendReflections;
 156      }
 157  
 158      /**
 159       * Return method reflection by name
 160       *
 161       * @param  string $name
 162       * @return MethodReflection
 163       */
 164      public function getMethod($name)
 165      {
 166          $method = new MethodReflection($this->getName(), parent::getMethod($name)->getName());
 167  
 168          return $method;
 169      }
 170  
 171      /**
 172       * Get reflection objects of all methods
 173       *
 174       * @param  int $filter
 175       * @return MethodReflection[]
 176       */
 177      public function getMethods($filter = -1)
 178      {
 179          $methods = [];
 180          foreach (parent::getMethods($filter) as $method) {
 181              $instance  = new MethodReflection($this->getName(), $method->getName());
 182              $methods[] = $instance;
 183          }
 184  
 185          return $methods;
 186      }
 187  
 188      /**
 189       * Returns an array of reflection classes of traits used by this class.
 190       *
 191       * @return null|array
 192       */
 193      public function getTraits()
 194      {
 195          $vals = [];
 196          $traits = parent::getTraits();
 197          if ($traits === null) {
 198              return;
 199          }
 200  
 201          foreach ($traits as $trait) {
 202              $vals[] = new ClassReflection($trait->getName());
 203          }
 204  
 205          return $vals;
 206      }
 207  
 208      /**
 209       * Get parent reflection class of reflected class
 210       *
 211       * @return ClassReflection|bool
 212       */
 213      public function getParentClass()
 214      {
 215          $phpReflection = parent::getParentClass();
 216          if ($phpReflection) {
 217              $zendReflection = new ClassReflection($phpReflection->getName());
 218              unset($phpReflection);
 219  
 220              return $zendReflection;
 221          }
 222  
 223          return false;
 224      }
 225  
 226      /**
 227       * Return reflection property of this class by name
 228       *
 229       * @param  string $name
 230       * @return PropertyReflection
 231       */
 232      public function getProperty($name)
 233      {
 234          $phpReflection  = parent::getProperty($name);
 235          $zendReflection = new PropertyReflection($this->getName(), $phpReflection->getName());
 236          unset($phpReflection);
 237  
 238          return $zendReflection;
 239      }
 240  
 241      /**
 242       * Return reflection properties of this class
 243       *
 244       * @param  int $filter
 245       * @return PropertyReflection[]
 246       */
 247      public function getProperties($filter = -1)
 248      {
 249          $phpReflections  = parent::getProperties($filter);
 250          $zendReflections = [];
 251          while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
 252              $instance          = new PropertyReflection($this->getName(), $phpReflection->getName());
 253              $zendReflections[] = $instance;
 254              unset($phpReflection);
 255          }
 256          unset($phpReflections);
 257  
 258          return $zendReflections;
 259      }
 260  
 261      /**
 262       * @return string
 263       */
 264      public function toString()
 265      {
 266          return parent::__toString();
 267      }
 268  
 269      /**
 270       * @return string
 271       */
 272      public function __toString()
 273      {
 274          return parent::__toString();
 275      }
 276  
 277      /**
 278       * Creates a new FileScanner instance.
 279       *
 280       * By having this as a separate method it allows the method to be overridden
 281       * if a different FileScanner is needed.
 282       *
 283       * @param  string $filename
 284       *
 285       * @return FileScanner
 286       */
 287      protected function createFileScanner($filename)
 288      {
 289          return new FileScanner($filename);
 290      }
 291  }


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1