public function parseSubElements()
 {
     /** @var \PHPParser_Node_Stmt_TraitUse $stmt  */
     foreach ($this->node->stmts as $stmt) {
         if ($stmt instanceof \PHPParser_Node_Stmt_TraitUse) {
             foreach ($stmt->traits as $trait) {
                 $this->traits[] = (string) $trait;
             }
         }
     }
     parent::parseSubElements();
 }
 /**
  * Interprets the PHP-Parser statement and constructs a class reflection.
  *
  * @param \PHPParser_Node_Stmt_Class $node A Class node as returned by the
  *     PHP-Parser component.
  */
 public function __construct(\PHPParser_Node_Stmt_Class $node)
 {
     parent::__construct($node);
     /** @var \PHPParser_Node_Stmt_TraitUse $stmt  */
     foreach ($node->stmts as $stmt) {
         if ($stmt instanceof \PHPParser_Node_Stmt_TraitUse) {
             foreach ($stmt->traits as $trait) {
                 $this->traits[] = (string) $trait;
             }
         }
     }
 }
示例#3
0
 public function enterNode(\PHPParser_Node $node)
 {
     $prettyPrinter = new \PHPParser_PrettyPrinter_Zend();
     switch (get_class($node)) {
         case 'PHPParser_Node_Stmt_Use':
             /** @var \PHPParser_Node_Stmt_UseUse $use */
             foreach ($node->uses as $use) {
                 $this->namespace_aliases[$use->alias] = implode('\\', $use->name->parts);
             }
             break;
         case 'PHPParser_Node_Stmt_Namespace':
             $this->current_namespace = implode('\\', $node->name->parts);
             break;
         case 'PHPParser_Node_Stmt_Class':
             $class = new ClassReflector($node);
             $class->setNamespaceAliases($this->namespace_aliases);
             $class->parseSubElements();
             $this->classes[] = $class;
             break;
         case 'PHPParser_Node_Stmt_Trait':
             $trait = new TraitReflector($node);
             $trait->setNamespaceAliases($this->namespace_aliases);
             $this->traits[] = $trait;
             break;
         case 'PHPParser_Node_Stmt_Interface':
             $interface = new InterfaceReflector($node);
             $interface->setNamespaceAliases($this->namespace_aliases);
             $interface->parseSubElements();
             $this->interfaces[] = $interface;
             break;
         case 'PHPParser_Node_Stmt_Function':
             $function = new FunctionReflector($node);
             $function->setNamespaceAliases($this->namespace_aliases);
             $this->functions[] = $function;
             break;
         case 'PHPParser_Node_Stmt_Const':
             foreach ($node->consts as $constant) {
                 $reflector = new ConstantReflector($node, $constant);
                 $reflector->setNamespaceAliases($this->namespace_aliases);
                 $this->constants[$reflector->getName()] = $reflector;
             }
             break;
         case 'PHPParser_Node_Expr_FuncCall':
             if ($node->name instanceof \PHPParser_Node_Name && $node->name == 'define') {
                 $name = trim($prettyPrinter->prettyPrintExpr($node->args[0]->value), '\'');
                 $constant = new \PHPParser_Node_Const($name, $node->args[1]->value, $node->getAttributes());
                 $constant->namespacedName = new \PHPParser_Node_Name(($this->current_namespace ? $this->current_namespace . '\\' : '') . $name);
                 // we use $constant here both times since this is a
                 // FuncCall, which combines properties that are otherwise
                 // split over 2 objects
                 $reflector = new ConstantReflector($constant, $constant);
                 $reflector->setNamespaceAliases($this->namespace_aliases);
                 $this->constants[$reflector->getName()] = $reflector;
             }
             break;
         case 'PHPParser_Node_Expr_Include':
             $include = new IncludeReflector($node);
             $include->setNamespaceAliases($this->namespace_aliases);
             $this->includes[] = $include;
             break;
     }
 }