/** * If a domainObject was renamed * * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $oldDomainObject * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $currentDomainObject * @return void */ protected function mapOldControllerToCurrentClassObject(Tx_ExtensionBuilder_Domain_Model_DomainObject $oldDomainObject, Tx_ExtensionBuilder_Domain_Model_DomainObject $currentDomainObject) { $extensionDir = $this->previousExtensionDirectory; $newClassName = $currentDomainObject->getControllerName(); $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(t3lib_div::lcfirst($oldName) . 'Repository'); $injectMethodName = 'inject' . $oldName . 'Repository'; if ($currentDomainObject->isAggregateRoot()) { // update the initializeAction method body $initializeMethod = $this->classObject->getMethod('initializeAction'); if ($initializeMethod != NULL) { $initializeMethodBody = $initializeMethod->getBody(); $newInitializeMethodBody = str_replace($oldDomainObject->getDomainRepositoryClassName(), $currentDomainObject->getDomainRepositoryClassName(), $initializeMethodBody); $newInitializeMethodBody = str_replace(t3lib_div::lcfirst($oldName) . 'Repository', t3lib_div::lcfirst($newName) . 'Repository', $newInitializeMethodBody); $initializeMethod->setBody($newInitializeMethodBody); $this->classObject->setMethod($initializeMethod); } $injectMethod = $this->classObject->getMethod($injectMethodName); if ($injectMethod != NULL) { $this->classObject->removeMethod($injectMethodName); $newInjectMethodBody = str_replace(t3lib_div::lcfirst($oldName), t3lib_div::lcfirst($newName), $injectMethod->getBody()); $injectMethod->setBody($newInjectMethodBody); $injectMethod->setTag('param', $currentDomainObject->getDomainRepositoryClassName() . ' $' . $newName . 'Repository'); $injectMethod->setName('inject' . $newName . 'Repository'); $parameter = new Tx_ExtensionBuilder_Domain_Model_Class_MethodParameter(t3lib_div::lcfirst($newName) . 'Repository'); $parameter->setTypeHint($currentDomainObject->getDomainRepositoryClassName()); $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->getBody(); $newActionMethodBody = str_replace(t3lib_div::lcfirst($oldName) . 'Repository', t3lib_div::lcfirst($newName) . 'Repository', $actionMethodBody); $actionMethod->setBody($newActionMethodBody); $actionMethod->setTag('param', $currentDomainObject->getClassName()); $parameters = $actionMethod->getParameters(); foreach ($parameters as &$parameter) { if (strpos($parameter->getTypeHint(), $oldDomainObject->getClassName()) > -1) { $parameter->setTypeHint($currentDomainObject->getClassName()); $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->setBody($this->replaceUpperAndLowerCase($oldName, $newName, $actionMethod->getBody())); $this->classObject->setMethod($actionMethod); } } } else { $this->classObject->removeMethod('initializeAction'); $this->classObject->removeMethod($injectMethodName); $this->cleanUp(Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($extensionDir, 'Repository'), $oldName . 'Repository.php'); } } $this->classObject->setFileName($newName . 'Controller.php'); $this->cleanUp(Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($extensionDir, 'Controller'), $oldName . 'Controller.php'); }