Ejemplo n.º 1
0
 function &createConstantReflector(&$value)
 {
     require_once 'Reflection/ConstantReflector.php';
     $reflector = new ConstantReflector();
     $reflector->setValue($value);
     return $reflector;
 }
Ejemplo n.º 2
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;
     }
 }
Ejemplo n.º 3
0
 public function enterNode(\PHPParser_Node $node)
 {
     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':
             $this->classes[] = new ClassReflector($node);
             break;
         case 'PHPParser_Node_Stmt_Trait':
             $this->traits[] = new TraitReflector($node);
             break;
         case 'PHPParser_Node_Stmt_Interface':
             $this->interfaces[] = new InterfaceReflector($node);
             break;
         case 'PHPParser_Node_Stmt_Function':
             $this->functions[] = new FunctionReflector($node);
             break;
         case 'PHPParser_Node_Stmt_Const':
             foreach ($node->consts as $constant) {
                 $reflector = new ConstantReflector($constant);
                 $this->constants[$reflector->getName()] = $reflector;
             }
             break;
         case 'PHPParser_Node_Expr_FuncCall':
             if ($node->name instanceof \PHPParser_Node_Name && $node->name == 'define') {
                 $constant = new \PHPParser_Node_Const($node->args[0]->value->value, $node->args[1]->value);
                 $constant->setLine($node->getLine());
                 $constant->namespacedName = new \PHPParser_Node_Name($this->current_namespace . '\\' . $constant->name);
                 $reflector = new ConstantReflector($constant);
                 $this->constants[$reflector->getName()] = $reflector;
             }
             break;
         case 'PHPParser_Node_Expr_Include':
             $this->includes[] = new IncludeReflector($node);
             break;
     }
 }