protected function onMethodEnd($trimmedLine) { if ($this->currentMethod['reflection']->getEndline() - $this->currentMethod['reflection']->getStartLine() >= 2) { $this->currentMethod['methodBody'] = $this->concatLinesFromArray($this->lines, $this->currentMethod['reflection']->getStartLine()); } else { $this->currentMethod['methodBody'] = ''; } if ($this->currentMethod['reflection']->getEndline() == $this->currentMethod['reflection']->getStartLine()) { // a one line method: we have to strip the method body from the rest $methodBodyRegex = '/\\{(.*)/'; $methodBodyMatches = array(); preg_match_all($methodBodyRegex, $this->currentLine, $methodBodyMatches); if (!empty($methodBodyMatches[1][0])) { $trimmedLine = trim($methodBodyMatches[1][0]); // trimmed line now still has a bracket at the end! } } if ($trimmedLine != '}' && strlen($trimmedLine) > 0) { // remove the bracket from last line $trimmedLine = substr(rtrim($trimmedLine), 0, -1); // add the trimmed $line $this->currentMethod['methodBody'] .= $trimmedLine; } $this->currentMethod['methodObject']->setBody($this->currentMethod['methodBody']); $this->classObject->addMethod($this->currentMethod['methodObject']); // end of a method body $this->inMethodBody = FALSE; $this->lastMatchedLineNumber = $this->lineCount; //TODO what if a method is defined in the same line as the preceding method ends? Should be checked with tokenizer? }
/** * 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; }