Пример #1
0
 /**
  * Create the Module.php content
  *
  * @return string
  */
 public function createModule()
 {
     // get needed options to shorten code
     $moduleName = $this->requestOptions->getModuleName();
     $modulePath = $this->requestOptions->getModulePath();
     $moduleFile = $modulePath . '/Module.php';
     $moduleViewDir = $this->requestOptions->getModuleViewDir();
     // create dirs
     mkdir($modulePath . '/config', 0777, true);
     mkdir($modulePath . '/src/' . $moduleName . '/Controller', 0777, true);
     mkdir($modulePath . '/view/' . $moduleViewDir, 0777, true);
     // create controller class with class generator
     $code = new ClassGenerator();
     $code->setNamespaceName($moduleName);
     $code->setName('Module');
     $code->addMethodFromGenerator($this->generateGetConfigMethod());
     $code->addMethodFromGenerator($this->generateGetAutoloaderConfigMethod());
     // add optional doc block
     if ($this->flagCreateApiDocs) {
         $code->setDocBlock(new DocBlockGenerator('Module', 'Please add a proper description for the ' . $moduleName . ' module', array($this->generatePackageTag($moduleName))));
     }
     // 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($moduleFile, $file->generate())) {
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * Create a module
  *
  * @return ConsoleModel
  */
 public function moduleAction()
 {
     // check for help mode
     if ($this->requestOptions->getFlagHelp()) {
         return $this->moduleHelp();
     }
     // output header
     $this->consoleHeader('Creating new module');
     // get needed options to shorten code
     $path = $this->requestOptions->getPath();
     $moduleName = $this->requestOptions->getModuleName();
     $modulePath = $this->requestOptions->getModulePath();
     $moduleViewDir = $this->requestOptions->getModuleViewDir();
     // 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 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 => ' already exists.')));
     }
     // write start message
     $this->console->write('       => Creating module class for module ');
     $this->console->writeLine($moduleName, Color::GREEN);
     // Create the Module.php
     $this->moduleGenerator->createModule();
     // write start message
     $this->console->write('       => Creating configuration for module ');
     $this->console->writeLine($moduleName, Color::GREEN);
     // Create the module.config.php
     $this->moduleGenerator->createConfiguration();
     // write start message
     $this->console->write('       => Adding module ');
     $this->console->write($moduleName, Color::GREEN);
     $this->console->writeLine(' to application configuration.');
     // add module configuration to application
     $applicationConfig = $this->moduleConfigurator->addModuleConfig();
     // check for module config updates
     if ($applicationConfig) {
         // update module configuration
         $configFlag = $this->moduleGenerator->updateConfiguration($applicationConfig, $path . '/config/application.config.php');
     }
     $this->console->writeLine();
     $this->console->write(' Done ', Color::NORMAL, Color::CYAN);
     $this->console->write(' ');
     $this->console->write('The module ');
     $this->console->write($moduleName, Color::GREEN);
     $this->console->write(' has been created');
     // success
     if ($path !== '.') {
         $this->console->write(' in ');
         $this->console->writeLine($path, Color::GREEN);
     } else {
         $this->console->writeLine();
     }
     // output footer
     $this->consoleFooter('module was successfully created');
 }