Ejemplo n.º 1
0
 /**
  * This method generates the repository class object,
  * which is passed to the template
  * it keeps all methods and properties including
  * user modified method bodies and comments
  * needed to create a repository class file
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @param boolean $mergeWithExistingClass
  *
  * @return \EBT\ExtensionBuilder\Domain\Model\File
  */
 public function generateRepositoryClassFileObject($domainObject, $repositoryTemplateClassPath, $mergeWithExistingClass)
 {
     $this->classObject = NULL;
     $className = $domainObject->getName() . 'Repository';
     $this->templateFileObject = $this->parserService->parseFile($repositoryTemplateClassPath);
     $this->templateClassObject = $this->templateFileObject->getFirstClass();
     if ($mergeWithExistingClass) {
         try {
             $this->classFileObject = $this->roundTripService->getRepositoryClassFile($domainObject);
             if ($this->classFileObject instanceof Model\File) {
                 $this->classObject = $this->classFileObject->getFirstClass();
             }
         } catch (\Exception $e) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Class ' . $className . ' could not be imported: ' . $e->getMessage(), 'extension_builder');
         }
     }
     if ($this->classObject == NULL) {
         $this->classFileObject = clone $this->templateFileObject;
         $this->classObject = clone $this->templateClassObject;
         $this->classObject->resetAll();
         $this->classObject->setName($className);
         $this->classObject->setNamespaceName($this->extension->getNamespaceName() . '\\Domain\\Repository');
         $this->classObject->setDescription('The repository for ' . Inflector::pluralize($domainObject->getName()));
         if (isset($this->settings['Repository']['parentClass'])) {
             $parentClass = $this->settings['Repository']['parentClass'];
         } else {
             $parentClass = '\\TYPO3\\CMS\\Extbase\\Persistence\\Repository';
         }
         $this->classObject->setParentClassName($parentClass);
     }
     $this->classFileObject->getNamespace()->setName($this->extension->getNamespaceName() . '\\Domain\\Repository')->setClasses(array($this->classObject));
     return $this->classFileObject;
 }
Ejemplo n.º 2
0
 /**
  * This method generates the repository class object,
  * which is passed to the template
  * it keeps all methods and properties including
  * user modified method bodies and comments
  * needed to create a repository class file
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @param \EBT\ExtensionBuilder\Domain\Model\File $existingClassFileObject
  *
  * @return \EBT\ExtensionBuilder\Domain\Model\File
  */
 public function generateRepositoryClassFileObject($domainObject, $repositoryTemplateClassPath, $existingClassFileObject = NULL)
 {
     $this->classObject = NULL;
     $className = $domainObject->getName() . 'Repository';
     $this->templateFileObject = $this->parserService->parseFile($repositoryTemplateClassPath);
     $this->templateClassObject = $this->templateFileObject->getFirstClass();
     if ($existingClassFileObject) {
         $this->classFileObject = $existingClassFileObject;
         $this->classObject = $existingClassFileObject->getFirstClass();
     }
     if ($this->classObject == NULL) {
         $this->classFileObject = clone $this->templateFileObject;
         $this->classObject = clone $this->templateClassObject;
         $this->classObject->resetAll();
         $this->classObject->setName($className);
         $this->classObject->setNamespaceName($this->extension->getNamespaceName() . '\\Domain\\Repository');
         $this->classObject->setDescription('The repository for ' . Inflector::pluralize($domainObject->getName()));
         if (isset($this->settings['Repository']['parentClass'])) {
             $parentClass = $this->settings['Repository']['parentClass'];
         } else {
             $parentClass = '\\TYPO3\\CMS\\Extbase\\Persistence\\Repository';
         }
         $this->classObject->setParentClassName($parentClass);
     }
     if ($domainObject->getSorting() && is_null($this->classObject->getProperty('defaultOrderings'))) {
         $defaultOrderings = $this->templateClassObject->getProperty('defaultOrderings');
         $this->classObject->addProperty($defaultOrderings);
     }
     $this->classFileObject->getNamespace()->setName($this->extension->getNamespaceName() . '\\Domain\\Repository')->setClasses(array($this->classObject));
     return $this->classFileObject;
 }
Ejemplo n.º 3
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 Node\Stmt\Class_) {
             if (count($this->contextStack) > 0) {
                 if (end($this->contextStack)->getType() == 'Stmt_Namespace') {
                     $currentNamespaceName = 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 Node\Stmt\Namespace_) {
             if (null !== $this->currentNamespace) {
                 $this->fileObject->addNamespace($this->currentNamespace);
                 $this->currentNamespace = null;
                 $this->currentContainer = $this->fileObject;
             } else {
                 //TODO: find how this could happen
             }
         } elseif ($node instanceof Node\Stmt\TraitUse) {
             if ($this->currentClassObject) {
                 $this->currentClassObject->addUseTraitStatement($node);
             }
         } elseif ($node instanceof Node\Stmt\Use_) {
             $this->currentContainer->addAliasDeclaration(NodeConverter::convertUseAliasStatementNodeToArray($node));
         } elseif ($node instanceof Node\Stmt\ClassConst) {
             $constants = NodeConverter::convertClassConstantNodeToArray($node);
             foreach ($constants as $constant) {
                 $this->currentContainer->setConstant($constant['name'], $constant['value']);
             }
         } elseif ($node instanceof Node\Stmt\ClassMethod) {
             $this->onFirstLevel = true;
             $method = $this->classFactory->buildClassMethodObject($node);
             $this->currentClassObject->addMethod($method);
         } elseif ($node instanceof Node\Stmt\Property) {
             $property = $this->classFactory->buildPropertyObject($node);
             $this->currentClassObject->addProperty($property);
         } elseif ($node instanceof Node\Stmt\Function_) {
             $this->onFirstLevel = true;
             $function = $this->classFactory->buildFunctionObject($node);
             $this->currentContainer->addFunction($function);
         } elseif (!$node instanceof 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);
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * update all relevant namespace parts in tags, typehints etc.
  */
 protected function updateVendorName()
 {
     $this->classObject->setNamespaceName($this->renameVendor($this->classObject->getNamespaceName()));
     foreach ($this->classObject->getProperties() as $property) {
         foreach ($property->getTags() as $tagName => $tagValue) {
             if (is_array($tagValue)) {
                 $tagValue = $tagValue[0];
             }
             if (!empty($tagValue)) {
                 $tagValue = $this->renameVendor($tagValue);
                 $property->setTag($tagName, $tagValue, true);
             }
         }
     }
     foreach ($this->classObject->getMethods() as $method) {
         foreach ($method->getTags() as $tagName => $tagValue) {
             if (is_array($tagValue)) {
                 $tagValue = $tagValue[0];
             }
             if (!empty($tagValue)) {
                 $tagValue = $this->renameVendor($tagValue);
                 $method->setTag($tagName, $tagValue, true);
             }
         }
         foreach ($method->getParameters() as $parameter) {
             $typeHint = $parameter->getTypeHint();
             if (!empty($typeHint)) {
                 $parameter->setTypeHint($this->renameVendor($typeHint));
             }
             $varType = $parameter->getVarType();
             if (!empty($varType)) {
                 $parameter->setVarType($this->renameVendor($varType));
             }
         }
     }
 }