Exemple #1
0
 /**
  * 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 \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @param \EBT\ExtensionBuilder\Domain\Model\File $existingClassFileObject
  *
  * @return \EBT\ExtensionBuilder\Domain\Model\File
  */
 public function generateRepositoryClassFileObject($domainObject, $repositoryTemplateClassPath, $existingClassFileObject = null)
 {
     $this->classObject = null;
     $className = $domainObject->getName() . 'Repository';
     $this->templateFileObject = $this->parserService->parseFile($repositoryTemplateClassPath);
     $this->templateClassObject = $this->templateFileObject->getFirstClass();
     if ($existingClassFileObject) {
         $this->classFileObject = $existingClassFileObject;
         $this->classObject = $existingClassFileObject->getFirstClass();
         if ($this->classFileObject->getNamespace() === false) {
             $nameSpace = new \EBT\ExtensionBuilder\Domain\Model\NamespaceObject('dummy');
             $this->classFileObject->addNamespace($nameSpace);
         }
     }
     if ($this->classObject == null) {
         $this->classFileObject = clone $this->templateFileObject;
         $this->classObject = clone $this->templateClassObject;
         $this->classObject->resetAll();
         $this->classObject->setName($className);
         $this->classObject->setDescription('The repository for ' . Inflector::pluralize($domainObject->getName()));
         if (isset($this->settings['Repository']['parentClass'])) {
             $parentClass = $this->settings['Repository']['parentClass'];
         } else {
             $parentClass = '\\TYPO3\\CMS\\Extbase\\Persistence\\Repository';
         }
         $this->classObject->setParentClassName($parentClass);
     }
     if ($domainObject->getSorting() && is_null($this->classObject->getProperty('defaultOrderings'))) {
         $defaultOrderings = $this->templateClassObject->getProperty('defaultOrderings');
         $this->classObject->addProperty($defaultOrderings);
     }
     $this->classFileObject->getNamespace()->setName($this->extension->getNamespaceName() . '\\Domain\\Repository')->setClasses(array($this->classObject));
     return $this->classFileObject;
 }
 /**
  * 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 \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @param boolean $mergeWithExistingClass
  *
  * @return \EBT\ExtensionBuilder\Domain\Model\File
  */
 public function generateRepositoryClassFileObject($domainObject, $repositoryTemplateClassPath, $mergeWithExistingClass)
 {
     $this->classObject = NULL;
     $className = $domainObject->getName() . 'Repository';
     $this->templateFileObject = $this->parserService->parseFile($repositoryTemplateClassPath);
     $this->templateClassObject = $this->templateFileObject->getFirstClass();
     if ($mergeWithExistingClass) {
         try {
             $this->classFileObject = $this->roundTripService->getRepositoryClassFile($domainObject);
             if ($this->classFileObject instanceof Model\File) {
                 $this->classObject = $this->classFileObject->getFirstClass();
             }
         } catch (\Exception $e) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Class ' . $className . ' could not be imported: ' . $e->getMessage(), 'extension_builder');
         }
     }
     if ($this->classObject == NULL) {
         $this->classFileObject = clone $this->templateFileObject;
         $this->classObject = clone $this->templateClassObject;
         $this->classObject->resetAll();
         $this->classObject->setName($className);
         $this->classObject->setNamespaceName($this->extension->getNamespaceName() . '\\Domain\\Repository');
         $this->classObject->setDescription('The repository for ' . Inflector::pluralize($domainObject->getName()));
         if (isset($this->settings['Repository']['parentClass'])) {
             $parentClass = $this->settings['Repository']['parentClass'];
         } else {
             $parentClass = '\\TYPO3\\CMS\\Extbase\\Persistence\\Repository';
         }
         $this->classObject->setParentClassName($parentClass);
     }
     $this->classFileObject->getNamespace()->setName($this->extension->getNamespaceName() . '\\Domain\\Repository')->setClasses(array($this->classObject));
     return $this->classFileObject;
 }
Exemple #3
0
 /**
  * Parse a file and compare the resulting
  * ClassObject with the reflection class object
  * @param $className
  * @return \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject
  */
 protected function parseClass($file, $className)
 {
     $classObject = $this->parserService->parseFile($file)->getFirstClass();
     $this->assertTrue($classObject instanceof \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject);
     require_once $file;
     $classReflection = new \TYPO3\CMS\Extbase\Reflection\ClassReflection($className);
     $this->ParserFindsAllConstants($classObject, $classReflection);
     $this->ParserFindsAllMethods($classObject, $classReflection);
     $this->ParserFindsAllProperties($classObject, $classReflection);
     $this->assertEquals($classReflection->getNamespaceName(), $classObject->getNamespaceName());
     return $classObject;
 }
Exemple #4
0
 protected function parseFile($relativeFilePath)
 {
     return $this->parserService->parseFile($this->fixturesPath . $relativeFilePath);
 }
Exemple #5
0
 /**
  * Replace all occurences of the old property name with the new name
  *
  * @param string $oldName
  * @param string $newName
  * @param string $string
  *
  * @return string
  */
 protected function replacePropertyNameInMethodBody($oldName, $newName, $methodBodyStmts)
 {
     return $this->parserService->replaceNodeProperty($methodBodyStmts, array($oldName => $newName));
 }
 protected function parseFile($fileName)
 {
     $classFilePath = $this->fixturesPath . $fileName;
     $classFileObject = $this->parserService->parseFile($classFilePath);
     return $classFileObject;
 }