Exemplo n.º 1
0
 /**
  * This method generates the class object, which is passed to the template
  * it keeps all methods and properties including user modified method bodies and
  * comments that are required to create a controller class file
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @param \EBT\ExtensionBuilder\Domain\Model\File $existingClassFileObject
  *
  * @return \EBT\ExtensionBuilder\Domain\Model\File
  */
 public function generateControllerClassFileObject($domainObject, $controllerClassTemplatePath, $existingClassFileObject = null)
 {
     $this->classObject = null;
     $className = $domainObject->getName() . 'Controller';
     $this->templateFileObject = $this->parserService->parseFile($controllerClassTemplatePath);
     $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->templateFileObject->getFirstClass();
         $this->classObject->resetAll();
         $this->classObject->setName($className);
         $this->classObject->setDescription($className);
         if (isset($this->settings['Controller']['parentClass'])) {
             $parentClass = $this->settings['Controller']['parentClass'];
         } else {
             $parentClass = '\\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController';
         }
         $this->classObject->setParentClassName($parentClass);
     }
     if ($domainObject->isAggregateRoot()) {
         $repositoryName = \TYPO3\CMS\Core\Utility\GeneralUtility::lcfirst($domainObject->getName() . 'Repository');
         // now add the property to class Object (or update an existing class Object property)
         if (!$this->classObject->propertyExists($repositoryName)) {
             $classProperty = $this->templateClassObject->getProperty('domainObjectRepository');
             $classProperty->setName($repositoryName);
             $classProperty->setDescription($repositoryName);
             $classProperty->setTag('var', $domainObject->getFullyQualifiedDomainRepositoryClassName(), true);
             $this->classObject->setProperty($classProperty);
         }
         if (!$this->classObject->getProperty($repositoryName)->isTaggedWith('inject') && !$this->classObject->methodExists('inject' . ucfirst($repositoryName))) {
             $this->classObject->getProperty($repositoryName)->setTag('inject');
         }
     }
     foreach ($domainObject->getActions() as $action) {
         $actionMethodName = $action->getName() . 'Action';
         if (!$this->classObject->methodExists($actionMethodName)) {
             $actionMethod = $this->buildActionMethod($action, $domainObject);
             $this->classObject->addMethod($actionMethod);
         }
     }
     $this->classFileObject->getNamespace()->setName($this->extension->getNamespaceName() . '\\Controller')->setClasses(array($this->classObject));
     return $this->classFileObject;
 }
Exemplo n.º 2
0
 /**
  * remove domainObject related files if a domainObject was deleted
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @return void
  */
 protected function removeDomainObjectFiles(Model\DomainObject $domainObject)
 {
     $this->log('Remove domainObject ' . $domainObject->getName());
     $this->cleanUp(FileGenerator::getFolderForClassFile($this->previousExtensionDirectory, 'Model', false), $domainObject->getName() . '.php');
     $this->cleanUp($this->previousExtensionDirectory . 'Configuration/TCA/', $domainObject->getName() . '.php');
     if ($domainObject->isAggregateRoot()) {
         $this->cleanUp(FileGenerator::getFolderForClassFile($this->previousExtensionDirectory, 'Controller', false), $domainObject->getName() . 'Controller.php');
         $this->cleanUp(FileGenerator::getFolderForClassFile($this->previousExtensionDirectory, 'Repository', false), $domainObject->getName() . 'Repository.php');
     }
     if (count($domainObject->getActions()) > 0) {
         $this->cleanUp(FileGenerator::getFolderForClassFile($this->previousExtensionDirectory, 'Controller', false), $domainObject->getName() . 'Controller.php');
     }
     // other files
     $iconsDirectory = $this->extensionDirectory . 'Resources/Public/Icons/';
     $languageDirectory = $this->extensionDirectory . 'Resources/Private/Language/';
     $locallang_cshFile = $languageDirectory . 'locallang_csh_' . $domainObject->getDatabaseTableName() . '.xml';
     $iconFile = $iconsDirectory . $domainObject->getDatabaseTableName() . '.gif';
     if (file_exists($locallang_cshFile)) {
         // no overwrite settings check here...
         unlink($locallang_cshFile);
         GeneralUtility::devLog('locallang_csh file removed: ' . $locallang_cshFile, 'extension_builder', 1);
     }
     if (file_exists($iconFile)) {
         unlink($iconFile);
         GeneralUtility::devLog('icon file removed: ' . $iconFile, 'extension_builder', 1);
     }
 }