예제 #1
0
 /**
  * @param \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject $classObject
  * @param bool $skipStatements
  * @return \PhpParser\Node\Stmt\Class_
  */
 public function buildClassNode($classObject, $skipStatements = false)
 {
     $factory = new \PhpParser\BuilderFactory();
     $classNodeBuilder = $factory->class($classObject->getName());
     if ($classObject->getParentClassName()) {
         $classNodeBuilder->extend(self::buildNodeFromName($classObject->getParentClassName()));
     }
     $interfaceNames = $classObject->getInterfaceNames();
     if (count($interfaceNames) > 0) {
         call_user_func_array(array($classNodeBuilder, 'implement'), $interfaceNames);
     }
     if (!$skipStatements) {
         $stmts = array();
         $properties = array();
         $methods = array();
         foreach ($classObject->getUseTraitStatement() as $statement) {
             $stmts[] = $statement;
         }
         foreach ($classObject->getMethods() as $method) {
             $methods[$method->getName()] = $this->buildMethodNode($method);
         }
         foreach ($classObject->getProperties() as $property) {
             $properties[$property->getName()] = $this->buildPropertyNode($property);
         }
         $constants = $classObject->getConstants();
         if (is_array($constants)) {
             foreach ($constants as $name => $value) {
                 $stmts[] = self::buildClassConstantNode($name, $value);
             }
         }
         foreach ($properties as $property) {
             $stmts[] = $property;
         }
         foreach ($methods as $method) {
             $stmts[] = $method;
         }
         $classNodeBuilder->addStmts($stmts);
     }
     $classNode = $classNodeBuilder->getNode();
     $classNode->type = $classObject->getModifiers();
     $this->addCommentAttributes($classObject, $classNode);
     return $classNode;
 }