public function getForeignModelName() { if (is_object($this->foreignModel)) { return $this->foreignModel->getName(); } $parts = explode('_Domain_Model_', $this->foreignClassName); return $parts[1]; }
/** * Add a domain object to the extension. Creates the reverse link as well. * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject */ public function addDomainObject(Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject) { $domainObject->setExtension($this); if (in_array($domainObject->getName(), array_keys($this->domainObjects))) { throw new Tx_ExtensionBuilder_Domain_Exception_ExtensionException('Duplicate domain object name "' . $domainObject->getName() . '".', Tx_ExtensionBuilder_Domain_Validator_ExtensionValidator::ERROR_DOMAINOBJECT_DUPLICATE); } if ($domainObject->getNeedsUploadFolder()) { $this->needsUploadFolder = TRUE; } $this->domainObjects[$domainObject->getName()] = $domainObject; }
/** * * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject * * @return Tx_ExtensionBuilder_Domain_Model_Class OR NULL */ public function getRepositoryClass(Tx_ExtensionBuilder_Domain_Model_DomainObject $currentDomainObject) { $extensionDir = $this->previousExtensionDirectory; if (isset($this->oldDomainObjects[$currentDomainObject->getUniqueIdentifier()])) { $oldDomainObject = $this->oldDomainObjects[$currentDomainObject->getUniqueIdentifier()]; $fileName = Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($extensionDir, 'Repository', FALSE) . $oldDomainObject->getName() . 'Repository.php'; if (file_exists($fileName)) { include_once $fileName; $className = $oldDomainObject->getDomainRepositoryClassName(); $this->classObject = $this->classParser->parse($className); if ($oldDomainObject->getName() != $currentDomainObject->getName() || $this->extensionRenamed) { $newClassName = $currentDomainObject->getDomainRepositoryClassName(); $this->classObject->setName($newClassName); $this->classObject->setFileName($currentDomainObject->getName() . '_Repository.php'); $this->cleanUp(Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($extensionDir, 'Repository'), $oldDomainObject->getName() . 'Repository.php'); } return $this->classObject; } else { t3lib_div::devLog('class file didn\'t exist:' . $fileName, 'extension_builder', 2); } } else { $fileName = Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($extensionDir, 'Repository', FALSE) . $currentDomainObject->getName() . 'Repository.php'; if (file_exists($fileName)) { include_once $fileName; $className = $currentDomainObject->getDomainRepositoryClassName(); $this->classObject = $this->classParser->parse($className); t3lib_div::devlog('existing Repository class:' . $fileName, 'extension_builder', 0, (array) $this->classObject); return $this->classObject; } } t3lib_div::devlog('No existing Repository class:' . $currentDomainObject->getName(), 'extension_builder', 2); return NULL; }
private function validateDomainObjectActions(Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject) { $actionNames = array(); $actions = $domainObject->getActions(); foreach ($actions as $action) { if (in_array($action->getName(), $actionNames)) { $this->validationResult['errors'][] = new Tx_ExtensionBuilder_Domain_Exception_ExtensionException('Duplicate action name "' . $action->getName() . '" of ' . $domainObject->getName() . '. Action names have to be unique for each model', self::ERROR_ACTIONNAME_DUPLICATE); } /** * Character test * Allowed characters are: a-z (lowercase), A-Z (uppercase) and 0-9 */ if (!preg_match("/^[a-zA-Z0-9]*\$/", $action->getName())) { $this->validationResult['errors'][] = new Tx_ExtensionBuilder_Domain_Exception_ExtensionException('Illegal action name "' . $action->getName() . '" of ' . $domainObject->getName() . '. Please use lowerCamelCase, no spaces or underscores.', self::ERROR_ACTIONNAME_ILLEGAL_CHARACTER); } $actionNames[] = $action->getName(); } $this->validateDependentActions($actionNames, 'Domain object ' . $domainObject->getName()); $firstAction = reset($actionNames); if ($firstAction == 'show' || $firstAction == 'edit' || $firstAction == 'delete') { $this->validationResult['warnings'][] = new Tx_ExtensionBuilder_Domain_Exception_ExtensionException('Potential misconfiguration in Domain object ' . $domainObject->getName() . ':<br />First action could not be default action since "' . $firstAction . '" action needs a parameter', self::ERROR_MISCONFIGURATION); } }
/** * This method generates the repository class object, which is passed to the template * it keeps all methods and properties including user modified method bodies and comments * needed to create a repository class file * * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject * @param boolean $mergeWithExistingClass * * @return Tx_ExtensionBuilder_Domain_Model_Class_Class */ public function generateRepositoryClassObject($domainObject, $mergeWithExistingClass) { t3lib_div::devlog('------------------------------------- generateRepositoryClassObject(' . $domainObject->getName() . ') ---------------------------------', 'extension_builder', 1); $this->classObject = NULL; $className = $domainObject->getDomainRepositoryClassName(); if ($mergeWithExistingClass) { try { $this->classObject = $this->roundTripService->getRepositoryClass($domainObject); } catch (Exception $e) { t3lib_div::devLog('Class ' . $className . ' could not be imported: ' . $e->getMessage(), 'extension_builder'); } } if ($this->classObject == NULL) { $this->classObject = new Tx_ExtensionBuilder_Domain_Model_Class_Class($className); if (isset($this->settings['Repository']['parentClass'])) { $parentClass = $this->settings['Repository']['parentClass']; } else { $parentClass = 'Tx_Extbase_Persistence_Repository'; } $this->classObject->setParentClass($parentClass); } return $this->classObject; }