/** * Create view script * * @return bool */ public function createViewScript() { // get needed options to shorten code $moduleName = $this->requestOptions->getModuleName(); $controllerName = $this->requestOptions->getControllerName(); $actionName = $this->requestOptions->getActionName(); $actionViewPath = $this->requestOptions->getActionViewPath(); $controllerViewPath = $this->requestOptions->getControllerViewPath(); // create dir if not exists if (!file_exists($controllerViewPath)) { mkdir($controllerViewPath, 0777, true); } // setup view script body $viewBody = array(); $viewBody[] = '?>'; $viewBody[] = '<div class="jumbotron">'; $viewBody[] = '<h1>Action "' . $actionName . '"</h1>'; $viewBody[] = '<p>Created for Controller "' . $controllerName . '" in Module "' . $moduleName . '"</p>'; $viewBody[] = '</div>'; // create file with file generator $file = new FileGenerator(); $file->setBody(implode(AbstractGenerator::LINE_FEED, $viewBody)); // add optional doc block if ($this->flagCreateApiDocs) { $file->setDocBlock(new DocBlockGenerator('View script generated by FrilleZFTool', null, array($this->generatePackageTag($moduleName)))); } // write view script if (!file_put_contents($actionViewPath, $file->generate())) { return false; } return true; }
/** * Show actions for a controller in a module */ public function actionsAction() { // check for help mode if ($this->requestOptions->getFlagHelp()) { return $this->actionsHelp(); } // output header $this->consoleHeader('Fetching requested information'); // get needed options to shorten code $path = $this->requestOptions->getPath(); $moduleName = $this->requestOptions->getModuleName(); $modulePath = $this->requestOptions->getModulePath(); $controllerKey = $this->requestOptions->getControllerKey(); $controllerName = $this->requestOptions->getControllerName(); $controllerPath = $this->requestOptions->getControllerPath(); $controllerFile = $this->requestOptions->getControllerFile(); // check for module path and application config if (!file_exists($path . '/module') || !file_exists($path . '/config/application.config.php')) { return $this->sendError(array(array(Color::NORMAL => 'The path '), array(Color::RED => $path), array(Color::NORMAL => ' doesn\'t contain a ZF2 application.'))); } // check if controller name provided if (!$controllerName) { return $this->sendError(array(array(Color::NORMAL => 'Please provide the controller name as parameter.'))); } // check if module name provided if (!$moduleName) { return $this->sendError(array(array(Color::NORMAL => 'Please provide the module name as parameter.'))); } // check if module exists if (!file_exists($modulePath)) { return $this->sendError(array(array(Color::NORMAL => 'The module '), array(Color::RED => $moduleName), array(Color::NORMAL => ' does not exist.'))); } // check if controller exists already in module if (!file_exists($controllerPath . $controllerFile)) { return $this->sendError(array(array(Color::NORMAL => 'The controller '), array(Color::RED => $controllerName), array(Color::NORMAL => ' does not exist in module '), array(Color::RED => $moduleName), array(Color::NORMAL => '.'))); } // get actions $actions = $this->getActionsForController($controllerPath . $controllerFile, $controllerKey); // check actions if (empty($actions)) { return $this->sendError(array(array(Color::NORMAL => 'No actions available for controller '), array(Color::RED => $controllerName), array(Color::NORMAL => ' in module '), array(Color::RED => $moduleName), array(Color::NORMAL => '.'))); } // start output $this->console->write(' Done ', Color::NORMAL, Color::CYAN); $this->console->write(' '); $this->console->write('Actions available in controller '); $this->console->write($controllerName, Color::GREEN); $this->console->write(' in module '); $this->console->write($moduleName, Color::GREEN); $this->console->writeLine(PHP_EOL); // output actions foreach ($actions as $actionMethod) { $this->console->writeLine(' => ' . $actionMethod . '()', Color::GREEN); } // output footer $this->consoleFooter('requested info was successfully displayed'); }
/** * Create an action method * * @return ConsoleModel */ public function methodAction() { // check for help mode if ($this->requestOptions->getFlagHelp()) { return $this->methodHelp(); } // output header $this->consoleHeader('Creating new action'); // get needed options to shorten code $path = $this->requestOptions->getPath(); $moduleName = $this->requestOptions->getModuleName(); $controllerName = $this->requestOptions->getControllerName(); $controllerPath = $this->requestOptions->getControllerPath(); $controllerClass = $this->requestOptions->getControllerClass(); $controllerFile = $this->requestOptions->getControllerFile(); $controllerViewPath = $this->requestOptions->getControllerViewPath(); $actionName = $this->requestOptions->getActionName(); $actionViewFile = $this->requestOptions->getActionViewFile(); // check for module path and application config if (!file_exists($path . '/module') || !file_exists($path . '/config/application.config.php')) { return $this->sendError(array(array(Color::NORMAL => 'The path '), array(Color::RED => $path), array(Color::NORMAL => ' doesn\'t contain a ZF2 application.'))); } // check if action name provided if (!$actionName) { return $this->sendError(array(array(Color::NORMAL => 'Please provide the action name as parameter.'))); } // check if controller name provided if (!$controllerName) { return $this->sendError(array(array(Color::NORMAL => 'Please provide the controller name as parameter.'))); } // check if module name provided if (!$moduleName) { return $this->sendError(array(array(Color::NORMAL => 'Please provide the module name as parameter.'))); } // check if controller exists already in module if (!file_exists($controllerPath . $controllerFile)) { return $this->sendError(array(array(Color::NORMAL => 'The controller '), array(Color::RED => $controllerName), array(Color::NORMAL => ' does not exist in module '), array(Color::RED => $moduleName), array(Color::NORMAL => '. I cannot create an action here.'))); } // write start message $this->console->write(' => Adding action '); $this->console->write($actionName, Color::GREEN); $this->console->write(' to controller '); $this->console->write($controllerName, Color::GREEN); $this->console->write(' in module '); $this->console->writeLine($moduleName, Color::GREEN); // update controller class try { $controllerFlag = $this->moduleGenerator->updateController(); } catch (GeneratorException $e) { $this->console->writeLine(); return $this->sendError(array(array(Color::NORMAL => 'The action '), array(Color::RED => $actionName), array(Color::NORMAL => ' already exists in controller '), array(Color::RED => $controllerName), array(Color::NORMAL => ' of module '), array(Color::RED => $moduleName), array(Color::NORMAL => '.'))); } // write start message $this->console->write(' => Creating view script '); $this->console->write($actionViewFile, Color::GREEN); $this->console->write(' in '); $this->console->writeLine($controllerViewPath, Color::GREEN); // create view script $viewScriptFlag = $this->moduleGenerator->createViewScript(); $this->console->writeLine(); $this->console->write(' Done ', Color::NORMAL, Color::CYAN); $this->console->write(' '); // write message $this->console->write('The action '); $this->console->write($actionName, Color::GREEN); $this->console->write(' has been created in controller '); $this->console->write($controllerName, Color::GREEN); $this->console->write(' of module '); $this->console->writeLine($moduleName, Color::GREEN); // output footer $this->consoleFooter('action was successfully created'); }