Ejemplo n.º 1
0
 /**
  * This method generates the class schema object, which is passed to the template
  * it keeps all methods and properties including user modified method bodies and
  * comments needed to create a domain object class file
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @param boolean $mergeWithExistingClass
  *
  * @return \EBT\ExtensionBuilder\Domain\Model\File
  */
 public function generateModelClassFileObject($domainObject, $modelClassTemplatePath, $mergeWithExistingClass)
 {
     $this->classObject = NULL;
     $fullQualifiedClassName = $domainObject->getFullQualifiedClassName();
     $this->templateFileObject = $this->parserService->parseFile($modelClassTemplatePath);
     $this->templateClassObject = $this->templateFileObject->getFirstClass();
     if ($mergeWithExistingClass) {
         try {
             $this->classFileObject = $this->roundTripService->getDomainModelClassFile($domainObject);
             if (!is_null($this->classFileObject)) {
                 $this->classObject = $this->classFileObject->getFirstClass();
             }
         } catch (\Exception $e) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Class ' . $fullQualifiedClassName . ' could not be imported: ' . $e->getMessage(), 'extension_builder', 2);
         }
     }
     if ($this->classObject == NULL) {
         $this->createNewModelClassObject($domainObject);
     }
     if (!$this->classObject->hasDescription() && $domainObject->getDescription()) {
         $this->classObject->setDescription($domainObject->getDescription());
     }
     $this->addInitStorageObjectCalls($domainObject);
     foreach ($domainObject->getProperties() as $domainProperty) {
         $this->addClassProperty($domainProperty);
         if ($domainProperty->isNew()) {
             $this->setPropertyRelatedMethods($domainProperty);
         }
     }
     $this->classFileObject->getNamespace()->setName($this->extension->getNamespaceName() . '\\Domain\\Model')->setClasses(array($this->classObject));
     return $this->classFileObject;
 }
Ejemplo n.º 2
0
 /**
  * Generates the code for the domain model class
  * Either from domainObject template or from class partial
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @param bool $mergeWithExistingClass
  * @return string
  */
 public function generateDomainObjectCode(\EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject)
 {
     $modelTemplateClassPath = $this->codeTemplateRootPath . 'Classes/Domain/Model/Model.phpt';
     $existingClassFileObject = null;
     if ($this->roundTripEnabled) {
         $existingClassFileObject = $this->roundTripService->getDomainModelClassFile($domainObject);
     }
     $modelClassFileObject = $this->classBuilder->generateModelClassFileObject($domainObject, $modelTemplateClassPath, $existingClassFileObject);
     if ($modelClassFileObject) {
         $this->addLicenseHeader($modelClassFileObject->getFirstClass());
         return $this->printerService->renderFileObject($modelClassFileObject, true);
     } else {
         throw new \Exception('Class file for domain object could not be generated');
     }
 }