/** * 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 boolean $mergeWithExistingClass * * @return \EBT\ExtensionBuilder\Domain\Model\File */ public function generateControllerClassFileObject($domainObject, $controllerClassTemplatePath, $mergeWithExistingClass) { $this->classObject = NULL; $className = $domainObject->getName() . 'Controller'; $this->templateFileObject = $this->parserService->parseFile($controllerClassTemplatePath); $this->templateClassObject = $this->templateFileObject->getFirstClass(); if ($mergeWithExistingClass) { try { $this->classFileObject = $this->roundTripService->getControllerClassFile($domainObject); if (!is_null($this->classFileObject)) { $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->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; }
/** * 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; }
/** * Rename a property and update comment (var tag and description) * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\AbstractProperty $oldProperty * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\AbstractProperty $newProperty * * @return void */ protected function updateProperty($oldProperty, $newProperty) { $classProperty = $this->classObject->getProperty($oldProperty->getName()); if ($classProperty) { $classProperty->setName($newProperty->getName()); $classProperty->setTag('var', $newProperty->getTypeForComment()); $newDescription = $newProperty->getDescription(); if (empty($newDescription) || $newDescription == $newProperty->getName()) { $newDescription = str_replace($oldProperty->getName(), $newProperty->getName(), $classProperty->getDescription()); } $classProperty->setDescription($newDescription); $this->classObject->removeProperty($oldProperty->getName()); $this->classObject->setProperty($classProperty); if ($this->relatedMethodsNeedUpdate($oldProperty, $newProperty)) { $this->updatePropertyRelatedMethods($oldProperty, $newProperty); } } }