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
 /**
  * Generates the code for the repository class
  * Either from domainRepository template or from class partial
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @param bool $mergeWithExistingClass
  *
  * @return string
  */
 public function generateDomainRepositoryCode(\EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject)
 {
     $repositoryTemplateClassPath = $this->codeTemplateRootPath . 'Classes/Domain/Repository/Repository.phpt';
     $existingClassFileObject = null;
     if ($this->roundTripEnabled) {
         $existingClassFileObject = $this->roundTripService->getRepositoryClassFile($domainObject);
     }
     $repositoryClassFileObject = $this->classBuilder->generateRepositoryClassFileObject($domainObject, $repositoryTemplateClassPath, $existingClassFileObject);
     if ($repositoryClassFileObject) {
         $this->addLicenseHeader($repositoryClassFileObject->getFirstClass());
         return $this->printerService->renderFileObject($repositoryClassFileObject, true);
     } else {
         throw new \Exception('Class file for repository could not be generated');
     }
 }