public function testGetTmpFileNameWrongCommit() { $commit = array('foo' => 'bar'); $path = sys_get_temp_dir(); $result = Skeleton::getTmpFileName($path, $commit); $this->assertEquals('', $result); }
/** * 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); }
/** * Create a project * * @return ConsoleModel */ public function projectAction() { // check for help mode if ($this->requestOptions->getFlagHelp()) { return $this->projectHelp(); } // output header $this->consoleHeader('Creating new Zend Framework 2 project'); // check for zip extension if (!extension_loaded('zip')) { return $this->sendError(array(array(Color::NORMAL => 'You need to install the ZIP extension of PHP.'))); } // check for openssl extension if (!extension_loaded('openssl')) { return $this->sendError(array(array(Color::NORMAL => 'You need to install the OpenSSL extension of PHP.'))); } // get needed options to shorten code $path = $this->requestOptions->getPath(); $tmpDir = $this->requestOptions->getTmpDir(); // check if path provided if ($path == '.') { return $this->sendError(array(array(Color::NORMAL => 'Please provide the path to create the project in.'))); } // check if path exists if (file_exists($path)) { return $this->sendError(array(array(Color::NORMAL => 'The directory '), array(Color::RED => $path), array(Color::NORMAL => ' already exists. '), array(Color::NORMAL => 'You cannot create a ZF2 project here.'))); } // check last commit $commit = Skeleton::getLastCommit(); if (false === $commit) { // error on github connection $tmpFile = Skeleton::getLastZip($tmpDir); if (empty($tmpFile)) { return $this->sendError(array(array(Color::NORMAL => 'I cannot access the API of GitHub.'))); } $this->console->writeLine('Warning: I cannot connect to GitHub, I will use the last ' . 'download of ZF2 Skeleton.', Color::LIGHT_RED); } else { $tmpFile = Skeleton::getTmpFileName($tmpDir, $commit); } // check for Skeleton App if (!file_exists($tmpFile)) { if (!Skeleton::getSkeletonApp($tmpFile)) { return $this->sendError(array(array(Color::NORMAL => 'I cannot access the ZF2 skeleton application in GitHub.'))); } } // set Zip Archive $zip = new \ZipArchive(); if ($zip->open($tmpFile)) { $stateIndex0 = $zip->statIndex(0); $tmpSkeleton = $tmpDir . '/' . rtrim($stateIndex0['name'], "/"); if (!$zip->extractTo($tmpDir)) { return $this->sendError(array(array(Color::NORMAL => 'Error during the unzip of '), array(Color::RED => $tmpFile), array(Color::NORMAL => '.'))); } $result = Utility::copyFiles($tmpSkeleton, $path); if (file_exists($tmpSkeleton)) { Utility::deleteFolder($tmpSkeleton); } $zip->close(); if (false === $result) { return $this->sendError(array(array(Color::NORMAL => 'Error during the copy of the files in '), array(Color::RED => $path), array(Color::NORMAL => '.'))); } } // check for composer if (file_exists($path . '/composer.phar')) { exec('php ' . $path . '/composer.phar self-update'); } else { if (!file_exists($tmpDir . '/composer.phar')) { if (!file_exists($tmpDir . '/composer_installer.php')) { file_put_contents($tmpDir . '/composer_installer.php', '?>' . file_get_contents('https://getcomposer.org/installer')); } exec('php ' . $tmpDir . '/composer_installer.php --install-dir ' . $tmpDir); } copy($tmpDir . '/composer.phar', $path . '/composer.phar'); } chmod($path . '/composer.phar', 0755); $this->console->write(' Done ', Color::NORMAL, Color::CYAN); $this->console->write(' '); $this->console->write('ZF2 skeleton application installed in '); $this->console->writeLine(realpath($path), Color::GREEN); $this->console->writeLine(); $this->console->writeLine(' => In order to execute the skeleton application you need to install the ZF2 library.'); $this->console->write(' => Execute: '); $this->console->write('composer.phar install', Color::GREEN); $this->console->write(' in '); $this->console->writeLine(realpath($path), Color::GREEN); $this->console->write(' => For more info please read '); $this->console->writeLine(realpath($path) . '/README.md', Color::GREEN); // output footer $this->consoleFooter('project was successfully created'); }
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); } }