/**
  * @param Node\Stmt\Const_ $node
  */
 protected function parseConstantNode(Node\Stmt\Const_ $node)
 {
     foreach ($node->consts as $const) {
         $this->globalConstants[] = ['name' => $const->name, 'startLine' => $node->getLine(), 'docComment' => $node->getDocComment() ? $node->getDocComment()->getText() : null];
     }
 }
Exemplo n.º 2
0
 public function leaveNode(Node $node)
 {
     $prettyPrinter = new PrettyPrinter();
     switch (get_class($node)) {
         case 'PhpParser\\Node\\Stmt\\Use_':
             /** @var \PhpParser\Node\Stmt\UseUse $use */
             foreach ($node->uses as $use) {
                 $this->context->setNamespaceAlias($use->alias, implode('\\', $use->name->parts));
             }
             break;
         case 'PhpParser\\Node\\Stmt\\Namespace_':
             $this->context->setNamespace(isset($node->name) && $node->name ? implode('\\', $node->name->parts) : '');
             break;
         case 'PhpParser\\Node\\Stmt\\Class_':
             $class = new ClassReflector($node, $this->context);
             $class->parseSubElements();
             $this->classes[] = $class;
             break;
         case 'PhpParser\\Node\\Stmt\\Trait_':
             $trait = new TraitReflector($node, $this->context);
             $trait->parseSubElements();
             $this->traits[] = $trait;
             break;
         case 'PhpParser\\Node\\Stmt\\Interface_':
             $interface = new InterfaceReflector($node, $this->context);
             $interface->parseSubElements();
             $this->interfaces[] = $interface;
             break;
         case 'PhpParser\\Node\\Stmt\\Function_':
             $function = new FunctionReflector($node, $this->context);
             $this->functions[] = $function;
             break;
         case 'PhpParser\\Node\\Stmt\\Const_':
             foreach ($node->consts as $constant) {
                 $reflector = new ConstantReflector($node, $this->context, $constant);
                 $this->constants[] = $reflector;
             }
             break;
         case 'PhpParser\\Node\\Expr\\FuncCall':
             if ($node->name instanceof Name && $node->name == 'define' && isset($node->args[0]) && isset($node->args[1])) {
                 // transform the first argument of the define function call into a constant name
                 $name = str_replace(array('\\\\', '"', "'"), array('\\', '', ''), trim($prettyPrinter->prettyPrintExpr($node->args[0]->value), '\''));
                 $nameParts = explode('\\', $name);
                 $shortName = end($nameParts);
                 $constant = new Const_($shortName, $node->args[1]->value, $node->getAttributes());
                 $constant->namespacedName = new Name($name);
                 $constant_statement = new ConstStmt(array($constant));
                 $constant_statement->setAttribute('comments', array($node->getDocComment()));
                 $this->constants[] = new ConstantReflector($constant_statement, $this->context, $constant);
             }
             break;
         case 'PhpParser\\Node\\Expr\\Include_':
             $include = new IncludeReflector($node, $this->context);
             $this->includes[] = $include;
             break;
     }
 }