/** * @param \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject $classObject * @param string $nameSpaceName * @param string $classDocComment * @return string */ protected function renderClassFile($classObject) { $nameSpace = new \EBT\ExtensionBuilder\Domain\Model\NamespaceObject($classObject->getNamespaceName()); $this->addLicenseHeader($classObject); $nameSpace->addClass($classObject); $classFile = new \EBT\ExtensionBuilder\Domain\Model\File(); $classFile->addNamespace($nameSpace); return $this->printerService->renderFileObject($classFile, true); }
/** * This method is the main part of the roundtrip functionality * It looks for a previous version of the current domain object and * parses the existing class file for that domain model * compares all properties and methods with the previous version. * * Methods are either removed/added or updated according to * the new property names * * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject The new domain object * * @return \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject OR NULL */ public function getDomainModelClassFile(Model\DomainObject $currentDomainObject) { if (isset($this->previousDomainObjects[$currentDomainObject->getUniqueIdentifier()])) { $this->log('domainObject identified:' . $currentDomainObject->getName()); $oldDomainObject = $this->previousDomainObjects[$currentDomainObject->getUniqueIdentifier()]; /** @var \EBT\ExtensionBuilder\Domain\Model\DomainObject $oldDomainObject */ $extensionDir = $this->previousExtensionDirectory; $fileName = FileGenerator::getFolderForClassFile($extensionDir, 'Model', FALSE) . $oldDomainObject->getName() . '.php'; if (file_exists($fileName)) { // import the classObject from the existing file $this->classFileObject = $this->parserService->parseFile($fileName); $this->classObject = $this->classFileObject->getFirstClass(); if ($oldDomainObject->getName() != $currentDomainObject->getName() || $this->extensionRenamed) { if (!$this->extensionRenamed) { $this->log('domainObject renamed. old: ' . $oldDomainObject->getName() . ' new: ' . $currentDomainObject->getName(), 'extension_builder'); } $newClassName = $currentDomainObject->getName(); $this->classObject->setName($newClassName); $this->classObject->setFileName($currentDomainObject->getName() . '.php'); $this->cleanUp(FileGenerator::getFolderForClassFile($extensionDir, 'Model'), $oldDomainObject->getName() . '.php'); $this->cleanUp($extensionDir . 'Configuration/TCA/', $oldDomainObject->getName() . '.php'); } else { $this->classObject->setName($currentDomainObject->getName()); } $this->updateModelClassProperties($oldDomainObject, $currentDomainObject); $newActions = array(); foreach ($currentDomainObject->getActions() as $newAction) { $newActions[$newAction->getName()] = $newAction; } $oldActions = $oldDomainObject->getActions(); if (empty($newActions) && !$currentDomainObject->isAggregateRoot() && (!empty($oldActions) || $oldDomainObject->isAggregateRoot())) { // remove the controller $this->cleanUp(FileGenerator::getFolderForClassFile($extensionDir, 'Controller'), $oldDomainObject->getName() . 'Controller.php'); } // the parent class settings configuration $parentClass = $currentDomainObject->getParentClass(); $oldParentClass = $oldDomainObject->getParentClass(); if (!empty($parentClass)) { if ($oldParentClass != $parentClass) { // the parent class was just new added $this->classObject->setParentClassName($parentClass); } } elseif (!empty($oldParentClass)) { // the old object had a parent class setting, but it's removed now if ($currentDomainObject->isEntity()) { $parentClass = $this->configurationManager->getParentClassForEntityObject($this->extension->getExtensionKey()); } else { $parentClass = $this->configurationManager->getParentClassForValueObject($this->extension->getExtensionKey()); } $this->classObject->setParentClassName($parentClass); } if ($currentDomainObject->isEntity() && !$oldDomainObject->isEntity()) { // the object type was changed in the modeler $this->classObject->setParentClassName($this->configurationManager->getParentClassForEntityObject($this->extension->getExtensionKey())); } elseif (!$currentDomainObject->isEntity() && $oldDomainObject->isEntity()) { // the object type was changed in the modeler $this->classObject->setParentClassName($this->configurationManager->getParentClassForValueObject($this->extension->getExtensionKey())); } $this->classFileObject->setClasses(array($this->classObject)); return $this->classFileObject; } else { GeneralUtility::devLog('class file didn\'t exist:' . $fileName, 'extension_builder', 0); } } else { $this->log('domainObject not identified:' . $currentDomainObject->getName(), 0, $this->previousDomainObjects); $fileName = FileGenerator::getFolderForClassFile($this->extensionDirectory, 'Model', FALSE); $fileName .= $currentDomainObject->getName() . '.php'; if (file_exists($fileName)) { // import the classObject from the existing file $this->classFileObject = $this->parserService->parseFile($fileName); $this->classObject = $this->classFileObject->getFirstClass(); $this->classObject->setFileName($fileName); $this->classObject->setName($currentDomainObject->getName()); $this->log('class file found:' . $currentDomainObject->getName() . '.php', 0, $this->classObject->getNamespaceName()); $this->classFileObject->setClasses(array($this->classObject)); return $this->classFileObject; } } return NULL; }
/** * update all relevant namespace parts in tags, typehints etc. */ protected function updateVendorName() { $this->classObject->setNamespaceName($this->renameVendor($this->classObject->getNamespaceName())); foreach ($this->classObject->getProperties() as $property) { foreach ($property->getTags() as $tagName => $tagValue) { if (is_array($tagValue)) { $tagValue = $tagValue[0]; } if (!empty($tagValue)) { $tagValue = $this->renameVendor($tagValue); $property->setTag($tagName, $tagValue, true); } } } foreach ($this->classObject->getMethods() as $method) { foreach ($method->getTags() as $tagName => $tagValue) { if (is_array($tagValue)) { $tagValue = $tagValue[0]; } if (!empty($tagValue)) { $tagValue = $this->renameVendor($tagValue); $method->setTag($tagName, $tagValue, true); } } foreach ($method->getParameters() as $parameter) { $typeHint = $parameter->getTypeHint(); if (!empty($typeHint)) { $parameter->setTypeHint($this->renameVendor($typeHint)); } $varType = $parameter->getVarType(); if (!empty($varType)) { $parameter->setVarType($this->renameVendor($varType)); } } } }
/** * @param \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject $classObject * @param string $nameSpaceName * @param string $classDocComment * @return string */ protected function renderClassFile($classObject) { $nameSpace = $this->objectManager->get('\\EBT\\ExtensionBuilder\\Domain\\Model\\NamespaceObject', $classObject->getNamespaceName()); $this->addLicenseHeader($classObject); $nameSpace->addClass($classObject); $classFile = $this->objectManager->get('\\EBT\\ExtensionBuilder\\Domain\\Model\\File'); $classFile->addNamespace($nameSpace); return $this->printerService->renderFileObject($classFile, TRUE); }