示例#1
0
 /**
  * @param PHPParser_Node $node
  */
 public function leaveNode(PHPParser_Node $node)
 {
     array_pop($this->contextStack);
     if ($this->isContainerNode(end($this->contextStack)) || count($this->contextStack) === 0) {
         // we are on the first level
         if ($node instanceof PHPParser_Node_Stmt_Class) {
             if (count($this->contextStack) > 0) {
                 if (end($this->contextStack)->getNodeType() == 'Stmt_Namespace') {
                     $currentNamespaceName = Tx_PhpParser_Parser_Utility_NodeConverter::getValueFromNode(end($this->contextStack));
                     $this->currentClassObject->setNamespaceName($currentNamespaceName);
                     $this->currentNamespace->addClass($this->currentClassObject);
                 }
             } else {
                 $this->fileObject->addClass($this->currentClassObject);
                 $this->currentClassObject = NULL;
                 $this->currentContainer = $this->fileObject;
             }
         } elseif ($node instanceof PHPParser_Node_Stmt_Namespace) {
             $this->fileObject->addNamespace($this->currentNamespace);
             $this->currentNamespace = NULL;
             $this->currentContainer = $this->fileObject;
         } elseif ($node instanceof PHPParser_Node_Stmt_Use) {
             $this->currentContainer->addAliasDeclaration($node);
         } elseif ($node instanceof PHPParser_Node_Stmt_ClassConst) {
             $constants = Tx_PhpParser_Parser_Utility_NodeConverter::convertClassConstantNodeToArray($node);
             foreach ($constants as $constant) {
                 $this->currentContainer->setConstant($constant['name'], $constant['value']);
             }
         } elseif ($node instanceof PHPParser_Node_Stmt_ClassMethod) {
             $this->onFirstLevel = TRUE;
             $method = $this->classFactory->buildClassMethodObjectFromNode($node);
             $this->currentClassObject->addMethod($method);
         } elseif ($node instanceof PHPParser_Node_Stmt_Property) {
             $property = $this->classFactory->buildPropertyObjectFromNode($node);
             $this->currentClassObject->addProperty($property);
         } elseif ($node instanceof PHPParser_Node_Stmt_Function) {
             $this->onFirstLevel = TRUE;
             $function = $this->classFactory->buildFunctionObjectFromNode($node);
             $this->currentContainer->addFunction($function);
         } elseif (!$node instanceof PHPParser_Node_Name) {
             // any other nodes (except the name node of the current container node)
             // go into statements container
             if ($this->currentContainer->getFirstClass() === FALSE) {
                 $this->currentContainer->addPreClassStatements($node);
             } else {
                 $this->currentContainer->addPostClassStatements($node);
             }
         }
     }
 }