/** * Export the $config array in a human readable format * * @param array $config * @param integer $space the initial indentation value * @return string */ public static function exportConfig($config, $indent = 0) { if (empty(static::$valueGenerator)) { static::$valueGenerator = new ValueGenerator(); } static::$valueGenerator->setValue($config); static::$valueGenerator->setArrayDepth($indent); return static::$valueGenerator; }
/** * Export the $config array in a human readable format * * @param array $config * @param int $indent the initial indentation value * @return string */ public static function exportConfig($config, $indent = 0) { if (empty(static::$valueGenerator)) { static::$valueGenerator = new ValueGenerator(); } static::$valueGenerator->setValue($config); static::$valueGenerator->setType(static::$useShortArrayNotation ? ValueGenerator::TYPE_ARRAY_SHORT : ValueGenerator::TYPE_ARRAY_LONG); static::$valueGenerator->setArrayDepth($indent); return static::$valueGenerator; }
public function testPropertyDefaultValueCanHandleComplexArrayOfTypes() { $targetValue = array(5, 'one' => 1, 'two' => '2', 'constant1' => '__DIR__ . \'/anydir1/anydir2\'', array('baz' => true, 'foo', 'bar', array('baz1', 'baz2', 'constant2' => 'ArrayObject::STD_PROP_LIST')), new ValueGenerator('PHP_EOL', 'constant')); $expectedSource = <<<EOS array( 5, 'one' => 1, 'two' => '2', 'constant1' => __DIR__ . '/anydir1/anydir2', array( 'baz' => true, 'foo', 'bar', array( 'baz1', 'baz2', 'constant2' => ArrayObject::STD_PROP_LIST ) ), PHP_EOL ) EOS; $valueGenerator = new ValueGenerator(); $valueGenerator->initEnvironmentConstants(); $valueGenerator->setValue($targetValue); $generatedTargetSource = $valueGenerator->generate(); $this->assertEquals($expectedSource, $generatedTargetSource); }
public function crudAction() { $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}/src/{$name}/Entity", 0777, true); mkdir("{$path}/module/{$name}/src/{$name}/Service", 0777, true); mkdir("{$path}/module/{$name}/view/{$viewfolder}/crud", 0777, true); $crudDir = __DIR__ . '/../../../data/crud'; $files = ["config/module.config.php" => "config/module.config.php", "autoload_classmap.php" => "autoload_classmap.php", "autoload_function.php" => "autoload_function.php", "autoload_register.php" => "autoload_register.php", "Module.php" => "Module.php", "src/{$name}/Controller/CrudController.php" => "src/LosCrudModule/Controller/CrudController.php", "src/{$name}/Entity/{$name}.php" => "src/LosCrudModule/Entity/Entity.php", "src/{$name}/Module.php" => "src/LosCrudModule/Module.php", "src/{$name}/Service/{$name}.php" => "src/LosCrudModule/Service/Entity.php", "view/{$viewfolder}/crud/add.phtml" => "view/los-crud-module/crud/add.phtml", "view/{$viewfolder}/crud/delete.phtml" => "view/los-crud-module/crud/delete.phtml", "view/{$viewfolder}/crud/edit.phtml" => "view/los-crud-module/crud/edit.phtml", "view/{$viewfolder}/crud/list.phtml" => "view/los-crud-module/crud/list.phtml"]; foreach ($files as $destFile => $origFile) { \file_put_contents("{$path}/module/{$name}/{$destFile}", $this->handleFile($crudDir . "/{$origFile}", $name, $viewfolder)); } // 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 changed by AcploBase * The previous configuration file is stored in application.config.old */ EOD; $generator = new ValueGenerator(); $generator->setValue($application); $content .= 'return ' . $generator . ";\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); } }
public function testPropertyDefaultValueCanHandleComplexArrayOfTypes() { $targetValue = array(5, 'one' => 1, 'two' => '2', array('foo', 'bar', array('baz1', 'baz2')), new ValueGenerator('PHP_EOL', 'constant')); $expectedSource = <<<EOS array( 5, 'one' => 1, 'two' => '2', array( 'foo', 'bar', array( 'baz1', 'baz2' ) ), PHP_EOL ) EOS; $valueGenerator = new ValueGenerator(); $valueGenerator->setValue($targetValue); $generatedTargetSource = $valueGenerator->generate(); $this->assertEquals($expectedSource, $generatedTargetSource); }
/** * @group ZF-7268 */ public function testDefaultValueGenerationDoesNotIncludeTrailingSemicolon() { $method = new MethodGenerator('setOptions'); $default = new ValueGenerator(); $default->setValue(array()); $param = new ParameterGenerator('options', 'array'); $param->setDefaultValue($default); $method->setParameter($param); $generated = $method->generate(); $this->assertRegexp('/array \$options = array\(\)\)/', $generated, $generated); }
/** * Generate the getConfig() method * * @return MethodGenerator */ protected function generateGetConfigMethod() { // create method body $body = new ValueGenerator(); $body->initEnvironmentConstants(); $body->setValue('include __DIR__ . \'/config/module.config.php\''); // create method $method = new MethodGenerator(); $method->setName('getConfig'); $method->setBody('return ' . $body->generate() . ';' . AbstractGenerator::LINE_FEED); // add optional doc block if ($this->flagCreateApiDocs) { $method->setDocBlock(new DocBlockGenerator('Get module configuration', null, array($this->generateReturnTag('array')))); } return $method; }
public function testPropertyDefaultValueCanHandleArrayWithUnsortedKeys() { $value = array(1 => 'a', 0 => 'b', 'c', 7 => 'd', 3 => 'e'); $valueGenerator = new ValueGenerator(); $valueGenerator->setValue($value); $expectedSource = <<<EOS array( 1 => 'a', 0 => 'b', 'c', 7 => 'd', 3 => 'e' ) EOS; $this->assertEquals($expectedSource, $valueGenerator->generate()); }
/** * Generate the getAutoloaderConfig() method * * @return void */ protected function addGetAutoloaderConfigMethod() { // set array data $array = ['Zend\\Loader\\ClassMapAutoloader' => ['__NAMESPACE__ => __DIR__ . \'/autoload_classmap.php\''], 'Zend\\Loader\\StandardAutoloader' => ['namespaces' => ['__NAMESPACE__ => __DIR__ . \'/src/\' . __NAMESPACE__']]]; // create method body $body = new ValueGenerator(); $body->initEnvironmentConstants(); $body->setValue($array); // create method $method = new MethodGenerator(); $method->setName('getAutoloaderConfig'); $method->setBody('return ' . $body->generate() . ';' . AbstractGenerator::LINE_FEED); // check for api docs if ($this->config['flagAddDocBlocks']) { $method->setDocBlock(new DocBlockGenerator('Get module autoloader configuration', 'Sets up the module autoloader configuration', [new ReturnTag(['array'], 'module autoloader configuration')])); } // add method $this->addMethodFromGenerator($method); $this->addUse('Zend\\ModuleManager\\Feature\\AutoloaderProviderInterface'); $this->setImplementedInterfaces(array_merge($this->getImplementedInterfaces(), ['AutoloaderProviderInterface'])); }