/** * * @return string The foreign class */ public function getForeignClassName() { if (isset($this->foreignClassName)) { return $this->foreignClassName; } if (is_object($this->foreignModel)) { return $this->foreignModel->getClassName(); } return NULL; }
/** * 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'); }
/** * This method generates the class schema object, which is passed to the template * it keeps all methods and properties including user modified method bodies and comments * needed to create a domain object class file * * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject * @param boolean mergeWithExistingClass * * @return Tx_ExtensionBuilder_Domain_Model_Class_Class */ public function generateModelClassObject($domainObject, $mergeWithExistingClass) { t3lib_div::devlog('------------------------------------- generateModelClassObject(' . $domainObject->getName() . ') ---------------------------------', 'extension_builder', 0); $this->classObject = NULL; // reference to the resulting class file, $className = $domainObject->getClassName(); if ($mergeWithExistingClass) { try { $this->classObject = $this->roundTripService->getDomainModelClass($domainObject); } catch (Exception $e) { t3lib_div::devLog('Class ' . $className . ' could not be imported: ' . $e->getMessage(), 'extension_builder', 2); } } if ($this->classObject == NULL) { $this->classObject = new Tx_ExtensionBuilder_Domain_Model_Class_Class($className); if ($domainObject->isEntity()) { $parentClass = $domainObject->getParentClass(); if (empty($parentClass)) { $parentClass = $this->configurationManager->getParentClassForEntityObject($this->extension->getExtensionKey()); } } else { $parentClass = $this->configurationManager->getParentClassForValueObject($this->extension->getExtensionKey()); } $this->classObject->setParentClass($parentClass); } if (!$this->classObject->hasDescription()) { $this->classObject->setDescription($domainObject->getDescription()); } $this->addInitStorageObjectCalls($domainObject); //TODO the following part still needs some enhancement: //what should be obligatory in existing properties and methods foreach ($domainObject->getProperties() as $domainProperty) { $propertyName = $domainProperty->getName(); // add the property to class Object (or update an existing class Object property) if ($this->classObject->propertyExists($propertyName)) { $classProperty = $this->classObject->getProperty($propertyName); //$classPropertyTags = $classProperty->getTags(); //t3lib_div::devLog('Property found: ' . $propertyName . ':' . $domainProperty->getTypeForComment(), 'extension_builder', 1, (array)$classProperty); } else { $classProperty = new Tx_ExtensionBuilder_Domain_Model_Class_Property($propertyName); $classProperty->setTag('var', $domainProperty->getTypeForComment()); $classProperty->addModifier('protected'); //t3lib_div::devLog('New property: ' . $propertyName . ':' . $domainProperty->getTypeForComment(), 'extension_builder', 1); } $classProperty->setAssociatedDomainObjectProperty($domainProperty); if ($domainProperty->getRequired()) { if (!$classProperty->isTaggedWith('validate')) { $validateTag = explode(' ', trim($domainProperty->getValidateAnnotation())); $classProperty->setTag('validate', $validateTag[1]); } } if ($domainProperty->isRelation() && $domainProperty->getLazyLoading()) { if (!$classProperty->isTaggedWith('lazy')) { $classProperty->setTag('lazy', ''); } } if ($domainProperty->getHasDefaultValue()) { $classProperty->setDefault($domainProperty->getDefaultValue()); } $this->classObject->setProperty($classProperty); if ($domainProperty->isNew()) { $this->setPropertyRelatedMethods($domainProperty); } } //t3lib_div::devlog('Methods before sorting','extension_builder',0,array_keys($this->classObject->getMethods())); //$this->sortMethods($domainObject); return $this->classObject; }