Source of file DerivedClassScanner.php
Size: 10,267 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Code/Scanner/DerivedClassScanner.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Code\Scanner; use Zend\Code\Exception; class DerivedClassScanner extends ClassScanner { /** * @var DirectoryScanner */ protected $directoryScanner = null; /** * @var ClassScanner */ protected $classScanner = null; /** * @var array */ protected $parentClassScanners = array(); /** * @var array */ protected $interfaceClassScanners = array(); /** * @param ClassScanner $classScanner * @param DirectoryScanner $directoryScanner */ public function __construct(ClassScanner $classScanner, DirectoryScanner $directoryScanner) { $this->classScanner = $classScanner; $this->directoryScanner = $directoryScanner; $currentScannerClass = $classScanner; while ($currentScannerClass && $currentScannerClass->hasParentClass()) { $currentParentClassName = $currentScannerClass->getParentClass(); if ($directoryScanner->hasClass($currentParentClassName)) { $currentParentClass = $directoryScanner->getClass($currentParentClassName); $this->parentClassScanners[$currentParentClassName] = $currentParentClass; $currentScannerClass = $currentParentClass; } else { $currentScannerClass = false; } } foreach ($interfaces = $this->classScanner->getInterfaces() as $iName) { if ($directoryScanner->hasClass($iName)) { $this->interfaceClassScanners[$iName] = $directoryScanner->getClass($iName); } } } /** * @return null|string */ public function getName() { return $this->classScanner->getName(); } /** * @return null|string */ public function getShortName() { return $this->classScanner->getShortName(); } /** * @return bool */ public function isInstantiable() { return $this->classScanner->isInstantiable(); } /** * @return bool */ public function isFinal() { return $this->classScanner->isFinal(); } /** * @return bool */ public function isAbstract() { return $this->classScanner->isAbstract(); } /** * @return bool */ public function isInterface() { return $this->classScanner->isInterface(); } /** * @return array */ public function getParentClasses() { return array_keys($this->parentClassScanners); } /** * @return bool */ public function hasParentClass() { return ($this->classScanner->getParentClass() != null); } /** * @return null|string */ public function getParentClass() { return $this->classScanner->getParentClass(); } /** * @param bool $returnClassScanners * @return array */ public function getInterfaces($returnClassScanners = false) { if ($returnClassScanners) { return $this->interfaceClassScanners; } $interfaces = $this->classScanner->getInterfaces(); foreach ($this->parentClassScanners as $pClassScanner) { $interfaces = array_merge($interfaces, $pClassScanner->getInterfaces()); } return $interfaces; } /** * Return a list of constant names * * @return array */ public function getConstantNames() { $constants = $this->classScanner->getConstantNames(); foreach ($this->parentClassScanners as $pClassScanner) { $constants = array_merge($constants, $pClassScanner->getConstantNames()); } return $constants; } /** * Return a list of constants * * @param bool $namesOnly Set false to return instances of ConstantScanner * @return array|ConstantScanner[] */ public function getConstants($namesOnly = true) { if (true === $namesOnly) { trigger_error('Use method getConstantNames() instead', E_USER_DEPRECATED); return $this->getConstantNames(); } $constants = $this->classScanner->getConstants(); foreach ($this->parentClassScanners as $pClassScanner) { $constants = array_merge($constants, $pClassScanner->getConstants($namesOnly)); } return $constants; } /** * Return a single constant by given name or index of info * * @param string|int $constantNameOrInfoIndex * @throws Exception\InvalidArgumentException * @return bool|ConstantScanner */ public function getConstant($constantNameOrInfoIndex) { if ($this->classScanner->hasConstant($constantNameOrInfoIndex)) { return $this->classScanner->getConstant($constantNameOrInfoIndex); } foreach ($this->parentClassScanners as $pClassScanner) { if ($pClassScanner->hasConstant($constantNameOrInfoIndex)) { return $pClassScanner->getConstant($constantNameOrInfoIndex); } } throw new Exception\InvalidArgumentException(sprintf( 'Constant %s not found in %s', $constantNameOrInfoIndex, $this->classScanner->getName() )); } /** * Verify if class or parent class has constant * * @param string $name * @return bool */ public function hasConstant($name) { if ($this->classScanner->hasConstant($name)) { return true; } foreach ($this->parentClassScanners as $pClassScanner) { if ($pClassScanner->hasConstant($name)) { return true; } } return false; } /** * Return a list of property names * * @return array */ public function getPropertyNames() { $properties = $this->classScanner->getPropertyNames(); foreach ($this->parentClassScanners as $pClassScanner) { $properties = array_merge($properties, $pClassScanner->getPropertyNames()); } return $properties; } /** * @param bool $returnScannerProperty * @return array */ public function getProperties($returnScannerProperty = false) { $properties = $this->classScanner->getProperties($returnScannerProperty); foreach ($this->parentClassScanners as $pClassScanner) { $properties = array_merge($properties, $pClassScanner->getProperties($returnScannerProperty)); } return $properties; } /** * Return a single property by given name or index of info * * @param string|int $propertyNameOrInfoIndex * @throws Exception\InvalidArgumentException * @return bool|PropertyScanner */ public function getProperty($propertyNameOrInfoIndex) { if ($this->classScanner->hasProperty($propertyNameOrInfoIndex)) { return $this->classScanner->getProperty($propertyNameOrInfoIndex); } foreach ($this->parentClassScanners as $pClassScanner) { if ($pClassScanner->hasProperty($propertyNameOrInfoIndex)) { return $pClassScanner->getProperty($propertyNameOrInfoIndex); } } throw new Exception\InvalidArgumentException(sprintf( 'Property %s not found in %s', $propertyNameOrInfoIndex, $this->classScanner->getName() )); } /** * Verify if class or parent class has property * * @param string $name * @return bool */ public function hasProperty($name) { if ($this->classScanner->hasProperty($name)) { return true; } foreach ($this->parentClassScanners as $pClassScanner) { if ($pClassScanner->hasProperty($name)) { return true; } } return false; } /** * @return array */ public function getMethodNames() { $methods = $this->classScanner->getMethodNames(); foreach ($this->parentClassScanners as $pClassScanner) { $methods = array_merge($methods, $pClassScanner->getMethodNames()); } return $methods; } /** * @return MethodScanner[] */ public function getMethods() { $methods = $this->classScanner->getMethods(); foreach ($this->parentClassScanners as $pClassScanner) { $methods = array_merge($methods, $pClassScanner->getMethods()); } return $methods; } /** * @param int|string $methodNameOrInfoIndex * @return MethodScanner * @throws Exception\InvalidArgumentException */ public function getMethod($methodNameOrInfoIndex) { if ($this->classScanner->hasMethod($methodNameOrInfoIndex)) { return $this->classScanner->getMethod($methodNameOrInfoIndex); } foreach ($this->parentClassScanners as $pClassScanner) { if ($pClassScanner->hasMethod($methodNameOrInfoIndex)) { return $pClassScanner->getMethod($methodNameOrInfoIndex); } } throw new Exception\InvalidArgumentException(sprintf( 'Method %s not found in %s', $methodNameOrInfoIndex, $this->classScanner->getName() )); } /** * Verify if class or parent class has method by given name * * @param string $name * @return bool */ public function hasMethod($name) { if ($this->classScanner->hasMethod($name)) { return true; } foreach ($this->parentClassScanners as $pClassScanner) { if ($pClassScanner->hasMethod($name)) { return true; } } return false; } } |