Exemple #1
0
 /**
  * generate all domainObject related
  * files like PHP class files, templates etc.
  *
  * @throws \Exception
  */
 protected function generateDomainObjectRelatedFiles()
 {
     if (count($this->extension->getDomainObjects()) > 0) {
         $this->classBuilder->initialize($this->extension);
         // Generate Domain Model
         try {
             $domainModelDirectory = 'Classes/Domain/Model/';
             $this->mkdir_deep($this->extensionDirectory, $domainModelDirectory);
             $domainRepositoryDirectory = 'Classes/Domain/Repository/';
             $this->mkdir_deep($this->extensionDirectory, $domainRepositoryDirectory);
             $this->mkdir_deep($this->extensionDirectory, 'Tests/Unit/Domain/Model');
             $domainModelTestsDirectory = $this->extensionDirectory . 'Tests/Unit/Domain/Model/';
             $this->mkdir_deep($this->extensionDirectory, 'Tests/Unit/Controller');
             $crudEnabledControllerTestsDirectory = $this->extensionDirectory . 'Tests/Unit/Controller/';
             foreach ($this->extension->getDomainObjects() as $domainObject) {
                 /**
                  * @var \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
                  */
                 $destinationFile = $domainModelDirectory . $domainObject->getName() . '.php';
                 if ($this->fileShouldBeMerged($destinationFile)) {
                     $mergeWithExistingClass = true;
                 } else {
                     $mergeWithExistingClass = false;
                 }
                 $fileContents = $this->generateDomainObjectCode($domainObject, $mergeWithExistingClass);
                 $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents);
                 GeneralUtility::devlog('Generated ' . $domainObject->getName() . '.php', 'extension_builder', 0);
                 $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile);
                 if ($domainObject->isAggregateRoot()) {
                     $iconFileName = 'aggregate_root.gif';
                 } elseif ($domainObject->isEntity()) {
                     $iconFileName = 'entity.gif';
                 } else {
                     $iconFileName = 'value_object.gif';
                 }
                 $this->upload_copy_move(ExtensionManagementUtility::extPath('extension_builder') . 'Resources/Private/Icons/' . $iconFileName, $this->iconsDirectory . $domainObject->getDatabaseTableName() . '.gif');
                 if ($domainObject->isAggregateRoot()) {
                     $destinationFile = $domainRepositoryDirectory . $domainObject->getName() . 'Repository.php';
                     if ($this->fileShouldBeMerged($destinationFile)) {
                         $mergeWithExistingClass = true;
                     } else {
                         $mergeWithExistingClass = false;
                     }
                     $fileContents = $this->generateDomainRepositoryCode($domainObject, $mergeWithExistingClass);
                     $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents);
                     GeneralUtility::devlog('Generated ' . $domainObject->getName() . 'Repository.php', 'extension_builder', 0);
                     $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile);
                 }
                 // Generate basic UnitTests
                 $fileContents = $this->generateDomainModelTests($domainObject);
                 $this->writeFile($domainModelTestsDirectory . $domainObject->getName() . 'Test.php', $fileContents);
             }
         } catch (\Exception $e) {
             throw new \Exception('Could not generate domain model, error: ' . $e->getMessage());
         }
         // Generate Action Controller
         try {
             $this->mkdir_deep($this->extensionDirectory, 'Classes/Controller');
             $controllerDirectory = 'Classes/Controller/';
             foreach ($this->extension->getDomainObjectsForWhichAControllerShouldBeBuilt() as $domainObject) {
                 $destinationFile = $controllerDirectory . $domainObject->getName() . 'Controller.php';
                 if ($this->fileShouldBeMerged($destinationFile)) {
                     $mergeWithExistingClass = true;
                 } else {
                     $mergeWithExistingClass = false;
                 }
                 $fileContents = $this->generateActionControllerCode($domainObject, $mergeWithExistingClass);
                 $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents);
                 GeneralUtility::devlog('Generated ' . $domainObject->getName() . 'Controller.php', 'extension_builder', 0);
                 $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile);
                 // Generate basic UnitTests
                 $fileContents = $this->generateControllerTests($domainObject->getName() . 'Controller', $domainObject);
                 $this->writeFile($crudEnabledControllerTestsDirectory . $domainObject->getName() . 'ControllerTest.php', $fileContents);
             }
         } catch (\Exception $e) {
             throw new \Exception('Could not generate action controller, error: ' . $e->getMessage());
         }
         // Generate Domain Templates
         try {
             if ($this->extension->getPlugins()) {
                 $this->generateTemplateFiles();
             }
             if ($this->extension->getBackendModules()) {
                 $this->generateTemplateFiles('Backend/');
             }
         } catch (\Exception $e) {
             throw new \Exception('Could not generate domain templates, error: ' . $e->getMessage());
         }
         try {
             $settings = $this->extension->getSettings();
         } catch (\Exception $e) {
             throw new \Exception('Could not generate ext_autoload.php, error: ' . $e->getMessage());
         }
     } else {
         GeneralUtility::devlog('No domainObjects in this extension', 'extension_builder', 3, (array) $this->extension);
     }
 }