/** * This method generates the class object, which is passed to the template * it keeps all methods and properties including user modified method bodies and * comments that are required to create a controller class file * * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject * @param boolean $mergeWithExistingClass * * @return Tx_ExtensionBuilder_Domain_Model_Class_Class */ public function generateControllerClassObject($domainObject, $mergeWithExistingClass) { t3lib_div::devlog('------------------------------------- generateControllerClassObject(' . $domainObject->getName() . ') ---------------------------------', 'extension_builder', 1); $this->classObject = NULL; $className = $domainObject->getControllerName(); if ($mergeWithExistingClass) { try { $this->classObject = $this->roundTripService->getControllerClass($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['Controller']['parentClass'])) { $parentClass = $this->settings['Controller']['parentClass']; } else { $parentClass = 'Tx_Extbase_MVC_Controller_ActionController'; } $this->classObject->setParentClass($parentClass); } if ($domainObject->isAggregateRoot()) { $propertyName = t3lib_div::lcfirst($domainObject->getName()) . 'Repository'; // now add the property to class Object (or update an existing class Object property) if (!$this->classObject->propertyExists($propertyName)) { $classProperty = new Tx_ExtensionBuilder_Domain_Model_Class_Property($propertyName); $classProperty->setTag('var', $domainObject->getDomainRepositoryClassName()); $classProperty->addModifier('protected'); $this->classObject->setProperty($classProperty); } $injectMethodName = 'inject' . $domainObject->getName() . 'Repository'; if (!$this->classObject->methodExists($injectMethodName)) { $repositoryVarName = t3lib_div::lcfirst($domainObject->getName()) . 'Repository'; $injectMethod = new Tx_ExtensionBuilder_Domain_Model_Class_Method($injectMethodName); $injectMethod->setBody('$this->' . $repositoryVarName . ' = $' . $repositoryVarName . ';'); $injectMethod->setTag('param', $domainObject->getDomainRepositoryClassName() . ' $' . $repositoryVarName); $injectMethod->setTag('return', 'void'); $injectMethod->addModifier('public'); $parameter = new Tx_ExtensionBuilder_Domain_Model_Class_MethodParameter($repositoryVarName); $parameter->setVarType($domainObject->getDomainRepositoryClassName()); $parameter->setTypeHint($domainObject->getDomainRepositoryClassName()); $parameter->setPosition(0); $injectMethod->setParameter($parameter); $this->classObject->addMethod($injectMethod); } } foreach ($domainObject->getActions() as $action) { $actionMethodName = $action->getName() . 'Action'; if (!$this->classObject->methodExists($actionMethodName)) { $actionMethod = $this->buildActionMethod($action, $domainObject); $this->classObject->addMethod($actionMethod); } } return $this->classObject; }
/** * If a method startline was found in the current line * @param array $methodMatches (regex matches) * @throws Tx_ExtensionBuilder_Exception_ParseError * @return void */ protected function onMethodFound($methodMatches) { $this->inMethodBody = TRUE; $methodName = $methodMatches['methodName'][0]; try { // the method has to exist in the classReflection $this->currentMethod['reflection'] = $this->classReflection->getMethod($methodName); if ($this->currentMethod['reflection']) { $classMethod = new Tx_ExtensionBuilder_Domain_Model_Class_Method($methodName, $this->currentMethod['reflection']); $precedingBlock = $this->concatLinesFromArray($this->lines, $this->lastMatchedLineNumber, NULL, FALSE); $classMethod->setPrecedingBlock($precedingBlock); $this->currentMethod['methodObject'] = $classMethod; } else { throw new Tx_ExtensionBuilder_Exception_ParseError('Method ' . $methodName . ' does not exist. Parsed from line ' . $this->lineCount . 'in ' . $this->classReflection->getFileName()); } } catch (ReflectionException $e) { // ReflectionClass throws an exception if a method was not found t3lib_div::devlog('Exception: ' . $e->getMessage(), 'extension_builder', 2); } }
/** * Add a method * * @param Tx_ExtensionBuilder_Domain_Model_Class_Method $classMethod * @return void */ public function addMethod($classMethod) { if (!$this->methodExists($classMethod->getName())) { $this->methods[$classMethod->getName()] = $classMethod; } }