コード例 #1
0
 /**
  * update means renaming of method name, parameter and replacing
  * parameter names in method body
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\AbstractProperty $oldProperty
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\AbstractProperty $newProperty
  * @param string $methodType get,set,add,remove,is
  *
  * @return void
  */
 protected function updateMethod($oldProperty, $newProperty, $methodType)
 {
     $oldMethodName = $this->classBuilder->getMethodName($oldProperty, $methodType);
     // the method to be merged
     $mergedMethod = $this->classObject->getMethod($oldMethodName);
     if (!$mergedMethod) {
         // no previous version of the method exists
         return;
     }
     $newMethodName = $this->classBuilder->getMethodName($newProperty, $methodType);
     $this->log('updateMethod:' . $oldMethodName . '=>' . $newMethodName, 'extension_builder');
     if ($oldProperty->getName() != $newProperty->getName()) {
         // rename the method
         $mergedMethod->setName($newMethodName);
         $oldMethodBody = $mergedMethod->getBodyStmts();
         $oldComment = $mergedMethod->getDocComment();
         $newMethodBody = $this->replacePropertyNameInMethodBody($oldProperty->getName(), $newProperty->getName(), $oldMethodBody);
         $mergedMethod->setBodyStmts($newMethodBody);
     }
     // update the method parameters
     $methodParameters = $mergedMethod->getParameters();
     if (!empty($methodParameters)) {
         $parameterTags = $mergedMethod->getTagValues('param');
         foreach ($methodParameters as $methodParameter) {
             $oldParameterName = $methodParameter->getName();
             if ($oldParameterName == $this->classBuilder->getParameterName($oldProperty, $methodType)) {
                 $newParameterName = $this->classBuilder->getParameterName($newProperty, $methodType);
                 $methodParameter->setName($newParameterName);
                 $newMethodBody = $this->replacePropertyNameInMethodBody($oldParameterName, $newParameterName, $mergedMethod->getBodyStmts());
                 $mergedMethod->setBodyStmts($newMethodBody);
             }
             $typeHint = $methodParameter->getTypeHint();
             if ($typeHint) {
                 if ($oldProperty->isRelation()) {
                     /** @var $oldProperty \EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\AbstractRelation */
                     if ($typeHint == $oldProperty->getForeignClassName()) {
                         $methodParameter->setTypeHint($this->updateExtensionKey($this->getForeignClassName($newProperty)));
                     }
                 }
             }
             $parameterTags[$methodParameter->getPosition()] = $this->classBuilder->getParamTag($newProperty, $methodType);
             $mergedMethod->replaceParameter($methodParameter);
         }
         $mergedMethod->setTag('param', $parameterTags);
     }
     $returnTagValue = $mergedMethod->getTagValues('return');
     if ($returnTagValue != 'void') {
         $mergedMethod->setTag('return', $newProperty->getTypeForComment() . ' ' . $newProperty->getName());
     }
     // replace property names in description
     $mergedMethod->setDescription(str_replace($oldProperty->getName(), $newProperty->getName(), $mergedMethod->getDescription()));
     if ($oldProperty instanceof AbstractRelation && $newProperty instanceof AbstractRelation) {
         $mergedMethod->setDescription(str_replace($oldProperty->getForeignClassName(), $newProperty->getForeignClassName(), $mergedMethod->getDescription()));
     }
     $this->classObject->removeMethod($oldMethodName);
     $this->classObject->addMethod($mergedMethod);
 }
コード例 #2
0
 /**
  * @test
  * @dataProvider propertyDefaultTypesProviderTypes
  */
 public function classBuilderGeneratesPropertyDefault($propertyName, $propertyDefaultValue)
 {
     $domainObject = $this->buildDomainObject($this->modelName, true, true);
     $propertyClassName = '\\EBT\\ExtensionBuilder\\Domain\\Model\\DomainObject\\' . ucfirst($propertyName) . 'Property';
     $property = new $propertyClassName($propertyName);
     $domainObject->addProperty($property);
     /** @var \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject $modelClassObject */
     $modelClassObject = $this->classBuilder->generateModelClassFileObject($domainObject, $this->modelClassTemplatePath, false)->getFirstClass();
     $propertyObject = $modelClassObject->getProperty($propertyName);
     self::assertSame($propertyDefaultValue, $propertyObject->getDefault());
 }
コード例 #3
0
 /**
  * Generates the code for the repository class
  * Either from domainRepository template or from class partial
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @param boolean $mergeWithExistingClass
  *
  * @return string
  */
 public function generateDomainRepositoryCode(\EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject, $mergeWithExistingClass)
 {
     $repositoryTemplateClassPath = $this->codeTemplateRootPath . 'Classes/Domain/Repository/Repository.phpt';
     $repositoryClassFileObject = $this->classBuilder->generateRepositoryClassFileObject($domainObject, $repositoryTemplateClassPath, $mergeWithExistingClass);
     if ($repositoryClassFileObject) {
         $this->addLicenseHeader($repositoryClassFileObject->getFirstClass());
         return $this->printerService->renderFileObject($repositoryClassFileObject, TRUE);
     } else {
         throw new \Exception('Class file for repository could not be generated');
     }
 }
コード例 #4
0
 protected function setUp($settingFile = '')
 {
     if (!class_exists('PHPParser_Parser')) {
         \EBT\ExtensionBuilder\Parser\AutoLoader::register();
     }
     if (!class_exists('PHPParser_Parser')) {
         die('Parser not found!!');
     }
     $this->fixturesPath = PATH_typo3conf . 'ext/extension_builder/Tests/Fixtures/';
     $this->extension = $this->getMock('EBT\\ExtensionBuilder\\Domain\\Model\\Extension', array('getExtensionDir'));
     $extensionKey = 'dummy';
     vfsStream::setup('testDir');
     $dummyExtensionDir = vfsStream::url('testDir') . '/';
     $this->extension->setVendorName('EBT');
     $this->extension->setExtensionKey($extensionKey);
     $this->extension->expects($this->any())->method('getExtensionDir')->will($this->returnValue($dummyExtensionDir));
     if (is_dir($dummyExtensionDir)) {
         GeneralUtility::mkdir($dummyExtensionDir, TRUE);
     }
     $yamlParser = new \EBT\ExtensionBuilder\Utility\SpycYAMLParser();
     $settings = $yamlParser->YAMLLoadString(file_get_contents($this->fixturesPath . 'Settings/settings1.yaml'));
     $this->extension->setSettings($settings);
     $configurationManager = GeneralUtility::makeInstance('EBT\\ExtensionBuilder\\Configuration\\ConfigurationManager');
     $this->roundTripService = $this->getMock($this->buildAccessibleProxy('EBT\\ExtensionBuilder\\Service\\RoundTrip'), array('dummy'));
     $this->classBuilder = GeneralUtility::makeInstance('EBT\\ExtensionBuilder\\Service\\ClassBuilder');
     $this->classBuilder->injectConfigurationManager($configurationManager);
     $this->roundTripService->injectClassBuilder($this->classBuilder);
     $this->roundTripService->injectConfigurationManager($configurationManager);
     $this->templateParser = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser'), array('dummy'));
     $this->fileGenerator = $this->getMock($this->buildAccessibleProxy('EBT\\ExtensionBuilder\\Service\\FileGenerator'), array('dummy'));
     $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $this->objectManager = clone $objectManager;
     $this->parserService = new \EBT\ExtensionBuilder\Service\Parser(new \PHPParser_Lexer());
     $this->printerService = new \EBT\ExtensionBuilder\Service\Printer();
     $this->printerService->injectNodeFactory(new \EBT\ExtensionBuilder\Parser\NodeFactory());
     $localizationService = $this->objectManager->get('EBT\\ExtensionBuilder\\Service\\LocalizationService');
     $this->fileGenerator->injectObjectManager($this->objectManager);
     $this->fileGenerator->injectPrinterService($this->printerService);
     $this->fileGenerator->injectLocalizationService($localizationService);
     $this->roundTripService->injectParserService($this->parserService);
     $this->roundTripService->initialize($this->extension);
     $this->classBuilder->injectRoundtripService($this->roundTripService);
     $this->classBuilder->injectParserService($this->parserService);
     $this->classBuilder->injectPrinterService($this->printerService);
     $this->classBuilder->injectClassFactory(new \EBT\ExtensionBuilder\Parser\ClassFactory());
     $this->classBuilder->initialize($this->fileGenerator, $this->extension, TRUE);
     $this->fileGenerator->injectClassBuilder($this->classBuilder);
     $this->codeTemplateRootPath = PATH_typo3conf . 'ext/extension_builder/Resources/Private/CodeTemplates/Extbase/';
     $this->modelClassTemplatePath = $this->codeTemplateRootPath . 'Classes/Domain/Model/Model.phpt';
     $this->fileGenerator->setSettings(array('codeTemplateRootPath' => $this->codeTemplateRootPath, 'extConf' => array('enableRoundtrip' => '1')));
     $this->fileGenerator->_set('codeTemplateRootPath', PATH_typo3conf . 'ext/extension_builder/Resources/Private/CodeTemplates/Extbase/');
     $this->fileGenerator->_set('enableRoundtrip', true);
     $this->fileGenerator->_set('extension', $this->extension);
 }
コード例 #5
0
 public function setUp()
 {
     parent::setUp();
     $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
     if (!class_exists('PhpParser\\Parser')) {
         throw new UnknownClassException('PhpParser not found!!');
     }
     $this->fixturesPath = __DIR__ . '/Fixtures/';
     $testTargetDir = 'testDir';
     vfsStream::setup($testTargetDir);
     $dummyExtensionDir = vfsStream::url($testTargetDir) . '/';
     $yamlParser = new \EBT\ExtensionBuilder\Utility\SpycYAMLParser();
     $settings = $yamlParser->YAMLLoadString(file_get_contents($this->fixturesPath . 'Settings/settings1.yaml'));
     $this->extension = $this->getMock(\EBT\ExtensionBuilder\Domain\Model\Extension::class, array('getExtensionDir'));
     $this->extension->setVendorName('EBT');
     $this->extension->setExtensionKey('dummy');
     $this->extension->expects($this->any())->method('getExtensionDir')->will($this->returnValue($dummyExtensionDir));
     if (is_dir($dummyExtensionDir)) {
         GeneralUtility::mkdir($dummyExtensionDir, TRUE);
     }
     $this->extension->setSettings($settings);
     // get instances to inject in Mocks
     $configurationManager = $this->objectManager->get(\EBT\ExtensionBuilder\Configuration\ConfigurationManager::class);
     $this->parserService = new \EBT\ExtensionBuilder\Service\Parser(new \PhpParser\Lexer());
     $this->printerService = $this->objectManager->get(\EBT\ExtensionBuilder\Service\Printer::class);
     $localizationService = $this->objectManager->get(\EBT\ExtensionBuilder\Service\LocalizationService::class);
     $this->classBuilder = $this->objectManager->get(\EBT\ExtensionBuilder\Service\ClassBuilder::class);
     $this->classBuilder->initialize($this->extension);
     $this->roundTripService = $this->getAccessibleMock(\EBT\ExtensionBuilder\Service\RoundTrip::class, array('dummy'));
     $this->inject($this->roundTripService, 'configurationManager', $configurationManager);
     $this->inject($this->roundTripService, 'parserService', $this->parserService);
     $this->roundTripService->initialize($this->extension);
     $this->fileGenerator = $this->getAccessibleMock(\EBT\ExtensionBuilder\Service\FileGenerator::class, array('dummy'));
     $this->inject($this->fileGenerator, 'objectManager', $this->objectManager);
     $this->inject($this->fileGenerator, 'printerService', $this->printerService);
     $this->inject($this->fileGenerator, 'localizationService', $localizationService);
     $this->inject($this->fileGenerator, 'classBuilder', $this->classBuilder);
     $this->inject($this->fileGenerator, 'roundTripService', $this->roundTripService);
     $this->codeTemplateRootPath = PATH_typo3conf . 'ext/extension_builder/Resources/Private/CodeTemplates/Extbase/';
     $this->modelClassTemplatePath = $this->codeTemplateRootPath . 'Classes/Domain/Model/Model.phpt';
     $this->fileGenerator->setSettings(array('codeTemplateRootPath' => $this->codeTemplateRootPath, 'extConf' => array('enableRoundtrip' => '1')));
     $this->fileGenerator->_set('codeTemplateRootPath', __DIR__ . '/../Resources/Private/CodeTemplates/Extbase/');
     $this->fileGenerator->_set('enableRoundtrip', true);
     $this->fileGenerator->_set('extension', $this->extension);
 }