/** * * @return string The foreign class */ public function getForeignClassName() { if (isset($this->foreignClassName)) { return $this->foreignClassName; } if (is_object($this->foreignModel)) { return $this->foreignModel->getFullQualifiedClassName(); } return NULL; }
/** * * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\Action $action * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject * * @return \EBT\ExtensionBuilder\Domain\Model\ClassObject\Method */ protected function buildActionMethod(Model\DomainObject\Action $action, Model\DomainObject $domainObject) { $actionName = $action->getName(); $actionMethodName = $actionName . 'Action'; if ($this->templateClassObject->methodExists($actionMethodName)) { $actionMethod = $this->templateClassObject->getMethod($actionMethodName); } else { $actionMethod = clone $this->templateClassObject->getMethod('genericAction'); $actionMethod->setName($actionMethodName); $actionMethod->setDescription('action ' . $action->getName()); } if (in_array($actionName, array('show', 'edit', 'create', 'update', 'delete'))) { // these actions need a parameter if (in_array($actionName, array('create'))) { $parameterName = 'new' . $domainObject->getName(); } else { $parameterName = \TYPO3\CMS\Core\Utility\GeneralUtility::lcfirst($domainObject->getName()); } $actionMethod->getParameterByPosition(0)->setName($parameterName)->setVarType($domainObject->getFullQualifiedClassName())->setTypeHint($domainObject->getFullQualifiedClassName()); $actionMethod->updateParamTags(); if ($actionName === 'edit') { $actionMethod->setTag('ignorevalidation', '$' . $parameterName); } } $replacements = array('domainObjectRepository' => lcfirst($domainObject->getName()) . 'Repository', 'domainObject' => lcfirst($domainObject->getName()), 'domainObjects' => lcfirst(Inflector::pluralize($domainObject->getName())), 'newDomainObject' => 'new' . $domainObject->getName()); $this->updateMethodBody($actionMethod, $replacements); $this->updateDocComment($actionMethod, $replacements); return $actionMethod; }
/** * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject1 * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject2 * @param array $classHierarchy * @return bool */ protected function isParentOf($domainObject1, $domainObject2, $classHierarchy) { if ($domainObject2->getParentClass() === $domainObject1->getFullQualifiedClassName()) { return TRUE; } else { return FALSE; } }
/** * If a domainObject was renamed * * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $oldDomainObject * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $currentDomainObject * @return void */ protected function mapOldControllerToCurrentClassObject(Model\DomainObject $oldDomainObject, Model\DomainObject $currentDomainObject) { $extensionDir = $this->previousExtensionDirectory; $newClassName = $currentDomainObject->getName() . 'Controller'; $newName = $currentDomainObject->getName(); $oldName = $oldDomainObject->getName(); $this->classObject->setName($newClassName); $this->classObject->setDescription($this->replaceUpperAndLowerCase($oldName, $newName, $this->classObject->getDescription())); if ($oldDomainObject->isAggregateRoot()) { // should we keep the old properties comments and tags? $this->classObject->removeProperty(GeneralUtility::lcfirst($oldName) . 'Repository'); $injectMethodName = 'inject' . $oldName . 'Repository'; if ($currentDomainObject->isAggregateRoot()) { // update the initializeAction method body $initializeMethod = $this->classObject->getMethod('initializeAction'); if ($initializeMethod != null) { $initializeMethodBodyStmts = $initializeMethod->getBodyStmts(); $initializeMethodBodyStmts = str_replace(GeneralUtility::lcfirst($oldName) . 'Repository', GeneralUtility::lcfirst($newName) . 'Repository', $initializeMethodBodyStmts); $initializeMethod->setBodyStmts($initializeMethodBodyStmts); $this->classObject->setMethod($initializeMethod); } $injectMethod = $this->classObject->getMethod($injectMethodName); if ($injectMethod != null) { $this->classObject->removeMethod($injectMethodName); $initializeMethodBodyStmts = str_replace(GeneralUtility::lcfirst($oldName), GeneralUtility::lcfirst($newName), $injectMethod->getBodyStmts()); $injectMethod->setBodyStmts($initializeMethodBodyStmts); $injectMethod->setTag('param', $currentDomainObject->getFullyQualifiedDomainRepositoryClassName() . ' $' . $newName . 'Repository'); $injectMethod->setName('inject' . $newName . 'Repository'); $parameter = new Model\ClassObject\MethodParameter(GeneralUtility::lcfirst($newName) . 'Repository'); $parameter->setTypeHint($currentDomainObject->getFullyQualifiedDomainRepositoryClassName()); $parameter->setPosition(0); $injectMethod->replaceParameter($parameter); $this->classObject->setMethod($injectMethod); } foreach ($oldDomainObject->getActions() as $action) { // here we have to update all the occurences of domain object names in action methods $actionMethod = $this->classObject->getMethod($action->getName() . 'Action'); if ($actionMethod != null) { $actionMethodBody = $actionMethod->getBodyStmts(); $newActionMethodBody = str_replace(GeneralUtility::lcfirst($oldName) . 'Repository', GeneralUtility::lcfirst($newName) . 'Repository', $actionMethodBody); $actionMethod->setBodyStmts($newActionMethodBody); $actionMethod->setTag('param', $currentDomainObject->getQualifiedClassName()); $parameters = $actionMethod->getParameters(); foreach ($parameters as &$parameter) { if (strpos($parameter->getTypeHint(), $oldDomainObject->getFullQualifiedClassName()) > -1) { $parameter->setTypeHint($currentDomainObject->getFullQualifiedClassName()); $parameter->setName($this->replaceUpperAndLowerCase($oldName, $newName, $parameter->getName())); $actionMethod->replaceParameter($parameter); } } $tags = $actionMethod->getTags(); foreach ($tags as $tagName => $tagValue) { $tags[$tagName] = $this->replaceUpperAndLowerCase($oldName, $newName, $tagValue); } $actionMethod->setTags($tags); $actionMethod->setDescription($this->replaceUpperAndLowerCase($oldName, $newName, $actionMethod->getDescription())); //TODO: this is not safe. Could rename unwanted variables $actionMethod->setBodyStmts($this->replaceUpperAndLowerCase($oldName, $newName, $actionMethod->getBodyStmts())); $this->classObject->setMethod($actionMethod); } } } else { $this->classObject->removeMethod('initializeAction'); $this->classObject->removeMethod($injectMethodName); $this->cleanUp(FileGenerator::getFolderForClassFile($extensionDir, 'Repository'), $oldName . 'Repository.php'); } } $this->classObject->setFileName($newName . 'Controller.php'); $this->cleanUp(FileGenerator::getFolderForClassFile($extensionDir, 'Controller'), $oldName . 'Controller.php'); }