/** * Método para adicionar um elemento * @param string $name Nome do input * @param array $options array do input */ public function addElement($name, $options) { // filters $arrayFilter = Skeleton::exportConfig($options); $this->element[$name] = <<<ELEMENT_FORM # ELEMENT {$name} # \$inputFilter->add({$arrayFilter}); ELEMENT_FORM; }
/** * Método para renderizar o metodo construtor e adicionar os elementos * @return [type] [description] */ protected function render() { $toString = ""; // Adiciona as opções do formulário $toString .= '$this->setOptions(' . Skeleton::exportConfig($this->options) . ');' . "\n"; // adiciona os elementos foreach ($this->element as $name => $elemento) { $toString .= $elemento; $toString .= '$this->add($' . $name . ');' . "\n"; } $this->classGenerator->addMethods(array(new Generator\MethodGenerator('__construct', array(), Generator\MethodGenerator::FLAG_PUBLIC, $toString))); }
public function testExportConfig() { $config = array('foo' => array('foo2' => 'bar2', 'foo3' => 'bar3'), 'bar'); $export = Skeleton::exportConfig($config); $expected = <<<EOD array( 'foo' => array( 'foo2' => 'bar2', 'foo3' => 'bar3', ), 'bar', ) EOD; $this->assertEquals($expected, (string) $export); }
public function moduleAction() { $console = $this->getServiceLocator()->get('console'); $tmpDir = sys_get_temp_dir(); $request = $this->getRequest(); $name = $request->getParam('name'); $path = rtrim($request->getParam('path'), '/'); if (empty($path)) { $path = '.'; } if (!file_exists("{$path}/module") || !file_exists("{$path}/config/application.config.php")) { return $this->sendError("The path {$path} doesn't contain a ZF2 application. I cannot create a module here."); } if (file_exists("{$path}/module/{$name}")) { return $this->sendError("The module {$name} already exists."); } $filter = new CamelCaseToDashFilter(); $viewfolder = strtolower($filter->filter($name)); $name = ucfirst($name); mkdir("{$path}/module/{$name}/config", 0777, true); mkdir("{$path}/module/{$name}/src/{$name}/Controller", 0777, true); mkdir("{$path}/module/{$name}/view/{$viewfolder}", 0777, true); // Create the Module.php file_put_contents("{$path}/module/{$name}/Module.php", Skeleton::getModule($name)); // Create the module.config.php file_put_contents("{$path}/module/{$name}/config/module.config.php", Skeleton::getModuleConfig($name)); // Add the module in application.config.php $application = (require "{$path}/config/application.config.php"); if (!in_array($name, $application['modules'])) { $application['modules'][] = $name; copy("{$path}/config/application.config.php", "{$path}/config/application.config.old"); $content = <<<EOD <?php /** * Configuration file generated by ZFTool * The previous configuration file is stored in application.config.old * * @see https://github.com/zendframework/ZFTool */ EOD; $content .= 'return ' . Skeleton::exportConfig($application) . ";\n"; file_put_contents("{$path}/config/application.config.php", $content); } if ($path === '.') { $console->writeLine("The module {$name} has been created", Color::GREEN); } else { $console->writeLine("The module {$name} has been created in {$path}", Color::GREEN); } }