コード例 #1
0
ファイル: ClassBuilder.php プロジェクト: maab127/default7
 /**
  *
  * create a new class object based on the template and the related domain object
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  *
  * @return void
  */
 protected function createNewModelClassObject($domainObject)
 {
     $this->classFileObject = clone $this->templateFileObject;
     $this->classObject = clone $this->templateFileObject->getFirstClass();
     $this->classObject->resetAll();
     // start with plain class
     $this->classObject->setName($domainObject->getName());
     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->setParentClassName($parentClass);
     $this->classObject->setDescription($domainObject->getDescription());
 }
コード例 #2
0
ファイル: RoundTrip.php プロジェクト: maab127/default7
 /**
  * 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));
             if ($this->extension->vendorNameChanged()) {
                 $this->updateVendorName();
             }
             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;
 }