Esempio n. 1
0
 /**
  *
  * @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;
 }
 /**
  * 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;
 }