/** * Update controller class with new action * * @return bool * @throws \Zend\Code\Generator\Exception */ public function updateController() { // get needed options to shorten code $moduleName = $this->requestOptions->getModuleName(); $controllerKey = $this->requestOptions->getControllerKey(); $controllerPath = $this->requestOptions->getControllerPath(); $controllerFile = $this->requestOptions->getControllerFile(); $actionMethod = $this->requestOptions->getActionMethod(); $controllerFilePath = $controllerPath . $controllerFile; // get file and class reflection $fileReflection = new FileReflection($controllerFilePath, true); $classReflection = $fileReflection->getClass($controllerKey . 'Controller'); // setup class generator with reflected class $code = ClassGenerator::fromReflection($classReflection); // check for action method if ($code->hasMethod($actionMethod)) { throw new GeneratorException('New action already exists within controller'); } // fix namespace usage $code->addUse('Zend\\Mvc\\Controller\\AbstractActionController'); $code->addUse('Zend\\View\\Model\\ViewModel'); $code->setExtendedClass('AbstractActionController'); $code->addMethodFromGenerator($this->generateActionMethod($actionMethod)); // create file with file generator $file = new FileGenerator(); $file->setClass($code); // add optional doc block if ($this->flagCreateApiDocs) { $file->setDocBlock(new DocBlockGenerator('This file was generated by FrilleZFTool.', null, array($this->generatePackageTag($moduleName), $this->generateSeeTag()))); } // write controller class if (!file_put_contents($controllerFilePath, $file->generate())) { return false; } return true; }