/** * $actions = $domainObject->getActions(); * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject * @return void */ private function validateDomainObjectActions(\EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject) { $actionNames = array(); $actions = $domainObject->getActions(); foreach ($actions as $action) { if (in_array($action->getName(), $actionNames)) { $this->validationResult['errors'][] = new ExtensionException('Duplicate action name "' . $action->getName() . '" of ' . $domainObject->getName() . LF . '; action names have to be unique for each model', self::ERROR_ACTIONNAME_DUPLICATE); } /** * Character test * Allowed characters are: a-z (lowercase), A-Z (uppercase) and 0-9 */ if (!preg_match('/^[a-zA-Z0-9]*$/', $action->getName())) { $this->validationResult['errors'][] = new ExtensionException('Illegal action name "' . $action->getName() . '" of ' . $domainObject->getName() . '.' . LF . 'Please use lowerCamelCase, no spaces or underscores.', self::ERROR_ACTIONNAME_ILLEGAL_CHARACTER); } $actionNames[] = $action->getName(); } $this->validateDependentActions($actionNames, 'Domain object ' . $domainObject->getName()); $firstAction = reset($actionNames); if ($firstAction == 'show' || $firstAction == 'edit' || $firstAction == 'delete') { $this->validationResult['warnings'][] = new ExtensionException('Potential misconfiguration in Domain object ' . $domainObject->getName() . ':' . LF . 'First action could not be default action since "' . $firstAction . '" action needs a parameter', self::ERROR_ACTION_MISCONFIGURATION); } }
/** * 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; }
/** * 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); } }