Changeset View
Changeset View
Standalone View
Standalone View
branches/5.3.x/core/kernel/utility/ClassDiscovery/ClassDetector.php
Show All 10 Lines | |||||
* or other free or open source software licenses. | * or other free or open source software licenses. | ||||
* See http://www.in-portal.org/license for copyright notices and details. | * See http://www.in-portal.org/license for copyright notices and details. | ||||
*/ | */ | ||||
namespace Intechnic\InPortal\Core\kernel\utility\ClassDiscovery; | namespace Intechnic\InPortal\Core\kernel\utility\ClassDiscovery; | ||||
use PhpParser\Node; | use PhpParser\Node; | ||||
use PhpParser\Node\Stmt\Class_; | |||||
use PhpParser\Node\Stmt\ClassLike; | use PhpParser\Node\Stmt\ClassLike; | ||||
use PhpParser\Node\Stmt\Interface_; | |||||
use PhpParser\Node\Stmt\Trait_; | |||||
use PhpParser\NodeVisitorAbstract; | use PhpParser\NodeVisitorAbstract; | ||||
defined('FULL_PATH') or die('restricted access!'); | defined('FULL_PATH') or die('restricted access!'); | ||||
class ClassDetector extends NodeVisitorAbstract | class ClassDetector extends NodeVisitorAbstract | ||||
{ | { | ||||
/** | /** | ||||
Show All 25 Lines | |||||
* | * | ||||
* @param Node $node Node. | * @param Node $node Node. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function enterNode(Node $node) | public function enterNode(Node $node) | ||||
{ | { | ||||
if ( $node instanceof ClassLike ) { | if ( $node instanceof ClassLike ) { | ||||
$this->classMapBuilder->addClass((string)$node->namespacedName); | $class_info = array(); | ||||
if ( $node instanceof Class_ ) { | |||||
$class_info['type'] = \kFactory::TYPE_CLASS; | |||||
$class_info['modifiers'] = 0; | |||||
if ( $node->isAbstract() ) { | |||||
$class_info['modifiers'] |= \kFactory::MODIFIER_ABSTRACT; | |||||
} | |||||
if ( $node->isFinal() ) { | |||||
$class_info['modifiers'] |= \kFactory::MODIFIER_FINAL; | |||||
} | |||||
$extends = array(); | |||||
if ( $node->extends ) { | |||||
$extends[] = (string)$node->extends; | |||||
} | |||||
if ( $node->implements ) { | |||||
foreach ( $node->implements as $interface ) { | |||||
$extends[] = (string)$interface; | |||||
} | |||||
} | |||||
if ( $extends ) { | |||||
$class_info['extends'] = $extends; | |||||
} | |||||
} | |||||
elseif ( $node instanceof Interface_ ) { | |||||
$class_info['type'] = \kFactory::TYPE_INTERFACE; | |||||
if ( $node->extends ) { | |||||
$extends = array(); | |||||
foreach ( $node->extends as $interface ) { | |||||
$extends[] = (string)$interface; | |||||
} | |||||
$class_info['extends'] = $extends; | |||||
} | |||||
} | |||||
elseif ( $node instanceof Trait_ ) { | |||||
$class_info['type'] = \kFactory::TYPE_TRAIT; | |||||
} | |||||
$this->classMapBuilder->addClass((string)$node->namespacedName, $class_info); | |||||
} | } | ||||
} | } | ||||
} | } |