/**
  * 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;
 }
Exemple #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->classFileObject->getNamespace() === false) {
             $nameSpace = new \EBT\ExtensionBuilder\Domain\Model\NamespaceObject('dummy');
             $this->classFileObject->addNamespace($nameSpace);
         }
     }
     if ($this->classObject == null) {
         $this->classFileObject = clone $this->templateFileObject;
         $this->classObject = clone $this->templateClassObject;
         $this->classObject->resetAll();
         $this->classObject->setName($className);
         $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;
 }
Exemple #3
0
 /**
  * @param \PhpParser\Node\Stmt\Class_ $classNode
  * @return \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject
  */
 public function buildClassObject(\PhpParser\Node\Stmt\Class_ $classNode)
 {
     $classObject = new Model\ClassObject\ClassObject($classNode->name);
     foreach ($classNode->implements as $interfaceNode) {
         $classObject->addInterfaceName($interfaceNode, false);
     }
     $classObject->setModifiers($classNode->type);
     if (!is_null($classNode->extends)) {
         $classObject->setParentClassName(NodeConverter::getValueFromNode($classNode->extends));
     }
     $this->addCommentsFromAttributes($classObject, $classNode);
     return $classObject;
 }
Exemple #4
0
 /**
  * This method is the main part of the roundtrip functionality
  * It looks for a previous version of the current domain object and
  * parses the existing class file for that domain model
  * compares all properties and methods with the previous version.
  *
  * Methods are either removed/added or updated according to
  * the new property names
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject The new domain object
  *
  * @return \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject OR null
  */
 public function getDomainModelClassFile(Model\DomainObject $currentDomainObject)
 {
     if (isset($this->previousDomainObjects[$currentDomainObject->getUniqueIdentifier()])) {
         $this->log('domainObject identified:' . $currentDomainObject->getName());
         $oldDomainObject = $this->previousDomainObjects[$currentDomainObject->getUniqueIdentifier()];
         /** @var \EBT\ExtensionBuilder\Domain\Model\DomainObject $oldDomainObject */
         $extensionDir = $this->previousExtensionDirectory;
         $fileName = FileGenerator::getFolderForClassFile($extensionDir, 'Model', false) . $oldDomainObject->getName() . '.php';
         if (file_exists($fileName)) {
             // import the classObject from the existing file
             $this->classFileObject = $this->parserService->parseFile($fileName);
             $this->classObject = $this->classFileObject->getFirstClass();
             if ($oldDomainObject->getName() != $currentDomainObject->getName() || $this->extensionRenamed) {
                 if (!$this->extensionRenamed) {
                     $this->log('domainObject renamed. old: ' . $oldDomainObject->getName() . ' new: ' . $currentDomainObject->getName(), 'extension_builder');
                 }
                 $newClassName = $currentDomainObject->getName();
                 $this->classObject->setName($newClassName);
                 $this->classObject->setFileName($currentDomainObject->getName() . '.php');
                 $this->cleanUp(FileGenerator::getFolderForClassFile($extensionDir, 'Model'), $oldDomainObject->getName() . '.php');
                 $this->cleanUp($extensionDir . 'Configuration/TCA/', $oldDomainObject->getName() . '.php');
             } else {
                 $this->classObject->setName($currentDomainObject->getName());
             }
             $this->updateModelClassProperties($oldDomainObject, $currentDomainObject);
             $newActions = array();
             foreach ($currentDomainObject->getActions() as $newAction) {
                 $newActions[$newAction->getName()] = $newAction;
             }
             $oldActions = $oldDomainObject->getActions();
             if (empty($newActions) && !$currentDomainObject->isAggregateRoot() && (!empty($oldActions) || $oldDomainObject->isAggregateRoot())) {
                 // remove the controller
                 $this->cleanUp(FileGenerator::getFolderForClassFile($extensionDir, 'Controller'), $oldDomainObject->getName() . 'Controller.php');
             }
             // the parent class settings configuration
             $parentClass = $currentDomainObject->getParentClass();
             $oldParentClass = $oldDomainObject->getParentClass();
             if (!empty($parentClass)) {
                 if ($oldParentClass != $parentClass) {
                     // the parent class was just new added
                     $this->classObject->setParentClassName($parentClass);
                 }
             } elseif (!empty($oldParentClass)) {
                 // the old object had a parent class setting, but it's removed now
                 if ($currentDomainObject->isEntity()) {
                     $parentClass = $this->configurationManager->getParentClassForEntityObject($this->extension->getExtensionKey());
                 } else {
                     $parentClass = $this->configurationManager->getParentClassForValueObject($this->extension->getExtensionKey());
                 }
                 $this->classObject->setParentClassName($parentClass);
             }
             if ($currentDomainObject->isEntity() && !$oldDomainObject->isEntity()) {
                 // the object type was changed in the modeler
                 $this->classObject->setParentClassName($this->configurationManager->getParentClassForEntityObject($this->extension->getExtensionKey()));
             } elseif (!$currentDomainObject->isEntity() && $oldDomainObject->isEntity()) {
                 // the object type was changed in the modeler
                 $this->classObject->setParentClassName($this->configurationManager->getParentClassForValueObject($this->extension->getExtensionKey()));
             }
             $this->classFileObject->setClasses(array($this->classObject));
             if ($this->extension->vendorNameChanged()) {
                 $this->updateVendorName();
             }
             return $this->classFileObject;
         } else {
             GeneralUtility::devLog('class file didn\'t exist:' . $fileName, 'extension_builder', 0);
         }
     } else {
         $this->log('domainObject not identified:' . $currentDomainObject->getName(), 0, $this->previousDomainObjects);
         $fileName = FileGenerator::getFolderForClassFile($this->extensionDirectory, 'Model', false);
         $fileName .= $currentDomainObject->getName() . '.php';
         if (file_exists($fileName)) {
             // import the classObject from the existing file
             $this->classFileObject = $this->parserService->parseFile($fileName);
             $this->classObject = $this->classFileObject->getFirstClass();
             $this->classObject->setFileName($fileName);
             $this->classObject->setName($currentDomainObject->getName());
             $this->log('class file found:' . $currentDomainObject->getName() . '.php', 0, $this->classObject->getNamespaceName());
             $this->classFileObject->setClasses(array($this->classObject));
             return $this->classFileObject;
         }
     }
     return null;
 }