[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/zendframework/zend-code/src/Scanner/ -> DerivedClassScanner.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\Scanner;
  11  
  12  use Zend\Code\Exception;
  13  
  14  use function array_keys;
  15  use function array_merge;
  16  use function sprintf;
  17  use function trigger_error;
  18  
  19  class DerivedClassScanner extends ClassScanner
  20  {
  21      /**
  22       * @var DirectoryScanner
  23       */
  24      protected $directoryScanner;
  25  
  26      /**
  27       * @var ClassScanner
  28       */
  29      protected $classScanner;
  30  
  31      /**
  32       * @var array
  33       */
  34      protected $parentClassScanners = [];
  35  
  36      /**
  37       * @var array
  38       */
  39      protected $interfaceClassScanners = [];
  40  
  41      /**
  42       * @param ClassScanner $classScanner
  43       * @param DirectoryScanner $directoryScanner
  44       */
  45      public function __construct(ClassScanner $classScanner, DirectoryScanner $directoryScanner)
  46      {
  47          $this->classScanner     = $classScanner;
  48          $this->directoryScanner = $directoryScanner;
  49  
  50          $currentScannerClass = $classScanner;
  51  
  52          while ($currentScannerClass && $currentScannerClass->hasParentClass()) {
  53              $currentParentClassName = $currentScannerClass->getParentClass();
  54              if ($directoryScanner->hasClass($currentParentClassName)) {
  55                  $currentParentClass = $directoryScanner->getClass($currentParentClassName);
  56                  $this->parentClassScanners[$currentParentClassName] = $currentParentClass;
  57                  $currentScannerClass = $currentParentClass;
  58              } else {
  59                  $currentScannerClass = false;
  60              }
  61          }
  62  
  63          foreach ($interfaces = $this->classScanner->getInterfaces() as $iName) {
  64              if ($directoryScanner->hasClass($iName)) {
  65                  $this->interfaceClassScanners[$iName] = $directoryScanner->getClass($iName);
  66              }
  67          }
  68      }
  69  
  70      /**
  71       * @return null|string
  72       */
  73      public function getName()
  74      {
  75          return $this->classScanner->getName();
  76      }
  77  
  78      /**
  79       * @return null|string
  80       */
  81      public function getShortName()
  82      {
  83          return $this->classScanner->getShortName();
  84      }
  85  
  86      /**
  87       * @return bool
  88       */
  89      public function isInstantiable()
  90      {
  91          return $this->classScanner->isInstantiable();
  92      }
  93  
  94      /**
  95       * @return bool
  96       */
  97      public function isFinal()
  98      {
  99          return $this->classScanner->isFinal();
 100      }
 101  
 102      /**
 103       * @return bool
 104       */
 105      public function isAbstract()
 106      {
 107          return $this->classScanner->isAbstract();
 108      }
 109  
 110      /**
 111       * @return bool
 112       */
 113      public function isInterface()
 114      {
 115          return $this->classScanner->isInterface();
 116      }
 117  
 118      /**
 119       * @return array
 120       */
 121      public function getParentClasses()
 122      {
 123          return array_keys($this->parentClassScanners);
 124      }
 125  
 126      /**
 127       * @return bool
 128       */
 129      public function hasParentClass()
 130      {
 131          return $this->classScanner->getParentClass() !== null;
 132      }
 133  
 134      /**
 135       * @return null|string
 136       */
 137      public function getParentClass()
 138      {
 139          return $this->classScanner->getParentClass();
 140      }
 141  
 142      /**
 143       * @param  bool $returnClassScanners
 144       * @return array
 145       */
 146      public function getInterfaces($returnClassScanners = false)
 147      {
 148          if ($returnClassScanners) {
 149              return $this->interfaceClassScanners;
 150          }
 151  
 152          $interfaces = $this->classScanner->getInterfaces();
 153          foreach ($this->parentClassScanners as $pClassScanner) {
 154              $interfaces = array_merge($interfaces, $pClassScanner->getInterfaces());
 155          }
 156  
 157          return $interfaces;
 158      }
 159  
 160      /**
 161       * Return a list of constant names
 162       *
 163       * @return array
 164       */
 165      public function getConstantNames()
 166      {
 167          $constants = $this->classScanner->getConstantNames();
 168          foreach ($this->parentClassScanners as $pClassScanner) {
 169              $constants = array_merge($constants, $pClassScanner->getConstantNames());
 170          }
 171  
 172          return $constants;
 173      }
 174  
 175      /**
 176       * Return a list of constants
 177       *
 178       * @param  bool $namesOnly Set false to return instances of ConstantScanner
 179       * @return array|ConstantScanner[]
 180       */
 181      public function getConstants($namesOnly = true)
 182      {
 183          if (true === $namesOnly) {
 184              trigger_error('Use method getConstantNames() instead', E_USER_DEPRECATED);
 185              return $this->getConstantNames();
 186          }
 187  
 188          $constants = $this->classScanner->getConstants();
 189          foreach ($this->parentClassScanners as $pClassScanner) {
 190              $constants = array_merge($constants, $pClassScanner->getConstants($namesOnly));
 191          }
 192  
 193          return $constants;
 194      }
 195  
 196      /**
 197       * Return a single constant by given name or index of info
 198       *
 199       * @param  string|int $constantNameOrInfoIndex
 200       * @throws Exception\InvalidArgumentException
 201       * @return bool|ConstantScanner
 202       */
 203      public function getConstant($constantNameOrInfoIndex)
 204      {
 205          if ($this->classScanner->hasConstant($constantNameOrInfoIndex)) {
 206              return $this->classScanner->getConstant($constantNameOrInfoIndex);
 207          }
 208  
 209          foreach ($this->parentClassScanners as $pClassScanner) {
 210              if ($pClassScanner->hasConstant($constantNameOrInfoIndex)) {
 211                  return $pClassScanner->getConstant($constantNameOrInfoIndex);
 212              }
 213          }
 214  
 215          throw new Exception\InvalidArgumentException(sprintf(
 216              'Constant %s not found in %s',
 217              $constantNameOrInfoIndex,
 218              $this->classScanner->getName()
 219          ));
 220      }
 221  
 222      /**
 223       * Verify if class or parent class has constant
 224       *
 225       * @param  string $name
 226       * @return bool
 227       */
 228      public function hasConstant($name)
 229      {
 230          if ($this->classScanner->hasConstant($name)) {
 231              return true;
 232          }
 233          foreach ($this->parentClassScanners as $pClassScanner) {
 234              if ($pClassScanner->hasConstant($name)) {
 235                  return true;
 236              }
 237          }
 238  
 239          return false;
 240      }
 241  
 242      /**
 243       * Return a list of property names
 244       *
 245       * @return array
 246       */
 247      public function getPropertyNames()
 248      {
 249          $properties = $this->classScanner->getPropertyNames();
 250          foreach ($this->parentClassScanners as $pClassScanner) {
 251              $properties = array_merge($properties, $pClassScanner->getPropertyNames());
 252          }
 253  
 254          return $properties;
 255      }
 256  
 257      /**
 258       * @param  bool $returnScannerProperty
 259       * @return array
 260       */
 261      public function getProperties($returnScannerProperty = false)
 262      {
 263          $properties = $this->classScanner->getProperties($returnScannerProperty);
 264          foreach ($this->parentClassScanners as $pClassScanner) {
 265              $properties = array_merge($properties, $pClassScanner->getProperties($returnScannerProperty));
 266          }
 267  
 268          return $properties;
 269      }
 270  
 271      /**
 272       * Return a single property by given name or index of info
 273       *
 274       * @param  string|int $propertyNameOrInfoIndex
 275       * @throws Exception\InvalidArgumentException
 276       * @return bool|PropertyScanner
 277       */
 278      public function getProperty($propertyNameOrInfoIndex)
 279      {
 280          if ($this->classScanner->hasProperty($propertyNameOrInfoIndex)) {
 281              return $this->classScanner->getProperty($propertyNameOrInfoIndex);
 282          }
 283  
 284          foreach ($this->parentClassScanners as $pClassScanner) {
 285              if ($pClassScanner->hasProperty($propertyNameOrInfoIndex)) {
 286                  return $pClassScanner->getProperty($propertyNameOrInfoIndex);
 287              }
 288          }
 289  
 290          throw new Exception\InvalidArgumentException(sprintf(
 291              'Property %s not found in %s',
 292              $propertyNameOrInfoIndex,
 293              $this->classScanner->getName()
 294          ));
 295      }
 296  
 297      /**
 298       * Verify if class or parent class has property
 299       *
 300       * @param  string $name
 301       * @return bool
 302       */
 303      public function hasProperty($name)
 304      {
 305          if ($this->classScanner->hasProperty($name)) {
 306              return true;
 307          }
 308          foreach ($this->parentClassScanners as $pClassScanner) {
 309              if ($pClassScanner->hasProperty($name)) {
 310                  return true;
 311              }
 312          }
 313  
 314          return false;
 315      }
 316  
 317      /**
 318       * @return array
 319       */
 320      public function getMethodNames()
 321      {
 322          $methods = $this->classScanner->getMethodNames();
 323          foreach ($this->parentClassScanners as $pClassScanner) {
 324              $methods = array_merge($methods, $pClassScanner->getMethodNames());
 325          }
 326  
 327          return $methods;
 328      }
 329  
 330      /**
 331       * @return MethodScanner[]
 332       */
 333      public function getMethods()
 334      {
 335          $methods = $this->classScanner->getMethods();
 336          foreach ($this->parentClassScanners as $pClassScanner) {
 337              $methods = array_merge($methods, $pClassScanner->getMethods());
 338          }
 339  
 340          return $methods;
 341      }
 342  
 343      /**
 344       * @param  int|string $methodNameOrInfoIndex
 345       * @return MethodScanner
 346       * @throws Exception\InvalidArgumentException
 347       */
 348      public function getMethod($methodNameOrInfoIndex)
 349      {
 350          if ($this->classScanner->hasMethod($methodNameOrInfoIndex)) {
 351              return $this->classScanner->getMethod($methodNameOrInfoIndex);
 352          }
 353  
 354          foreach ($this->parentClassScanners as $pClassScanner) {
 355              if ($pClassScanner->hasMethod($methodNameOrInfoIndex)) {
 356                  return $pClassScanner->getMethod($methodNameOrInfoIndex);
 357              }
 358          }
 359  
 360          throw new Exception\InvalidArgumentException(sprintf(
 361              'Method %s not found in %s',
 362              $methodNameOrInfoIndex,
 363              $this->classScanner->getName()
 364          ));
 365      }
 366  
 367      /**
 368       * Verify if class or parent class has method by given name
 369       *
 370       * @param  string $name
 371       * @return bool
 372       */
 373      public function hasMethod($name)
 374      {
 375          if ($this->classScanner->hasMethod($name)) {
 376              return true;
 377          }
 378          foreach ($this->parentClassScanners as $pClassScanner) {
 379              if ($pClassScanner->hasMethod($name)) {
 380                  return true;
 381              }
 382          }
 383  
 384          return false;
 385      }
 386  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1