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 updateGeneratedResources() { foreach ($this->constants as $value) { $this->constantGenerator->generateFromNeonFile($this->configuration->getDir() . DIRECTORY_SEPARATOR . $value); } foreach ($this->values as $value) { $this->valueGenerator->generateFromNeonFile($this->configuration->getDir() . DIRECTORY_SEPARATOR . $value); } }
/** * 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 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); } }
private function generateConfig() { $allClasses = get_declared_classes(); $classList = []; foreach ($allClasses as $class) { $class = new ClassReflection($class); if ($this->shouldSkip($class)) { continue; } $classList[] = $class->getName(); } $generator = new ValueGenerator($classList); return $generator->generate(); }
/** * generate() * * @return string */ public function generate() { $output = ''; if ($this->type && !in_array($this->type, self::$simple)) { $output .= $this->type . ' '; } if ($this->passedByReference === true) { $output .= '&'; } $output .= '$' . $this->name; if ($this->defaultValue !== null) { $output .= ' = '; if (is_string($this->defaultValue)) { $output .= ValueGenerator::escape($this->defaultValue); } else { if ($this->defaultValue instanceof ValueGenerator) { $this->defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE); $output .= (string) $this->defaultValue; } else { $output .= $this->defaultValue; } } } return $output; }
/** * @param array $configData * @param Parameters $params */ public function __construct(array $configData = [], Parameters $params) { // set params $this->params = $params; // reset constant compilation $configData = $this->resetConfigDirCompilation($configData); $configData = $this->resetTemplateMapCompilation($configData); // call parent constructor parent::__construct($configData, ValueGenerator::TYPE_ARRAY); // init constants $this->initEnvironmentConstants(); $this->addConstant($this->params->moduleRootConstant); $this->addConstant($this->params->applicationRootConstant); }
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); }
/** * @return string */ public function generate() { $output = $this->generateTypeHint(); if (true === $this->passedByReference) { $output .= '&'; } if ($this->variadic) { $output .= '... '; } $output .= '$' . $this->name; if ($this->defaultValue !== null) { $output .= ' = '; if (is_string($this->defaultValue)) { $output .= ValueGenerator::escape($this->defaultValue); } elseif ($this->defaultValue instanceof ValueGenerator) { $this->defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE); $output .= $this->defaultValue; } else { $output .= $this->defaultValue; } } return $output; }
/** * @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 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'])); }
/** * @return string */ private function generateDefaultValue() { if (null === $this->defaultValue) { return ''; } if (is_string($this->defaultValue)) { return ' = ' . ValueGenerator::escape($this->defaultValue); } if ($this->defaultValue instanceof ValueGenerator) { $this->defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE); } return ' = ' . $this->defaultValue; }
/** * @group 6023 * * @dataProvider getEscapedParameters */ public function testEscaping($input, $expectedEscapedValue) { $this->assertSame($expectedEscapedValue, ValueGenerator::escape($input, false)); }
protected function coolFormat($array) { $generator = new ValueGenerator($array); return $generator->generate(); }
/** * 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; }
$extendedClass = $resourceFile->getClass()->getExtendedClass(); if (in_array($resourceFile->getClass()->getName(), $requestTypes) || in_array($extendedClass, $requestTypes)) { $type = $requestNamespacePart; $resourceFile->getClass()->setNamespaceName($requestNamespace); if (!$extendedClass) { $resourceFile->getClass()->setExtendedClass(SoapGenerator::ABSTRACT_REQUEST_ALIAS)->addUse("{$namespace}\\{$soapNamespace}\\AbstractRequest", SoapGenerator::ABSTRACT_REQUEST_ALIAS); } } elseif (in_array($resourceFile->getClass()->getName(), $responseTypes) || in_array($extendedClass, $responseTypes)) { $type = $responseNamespacePart; $resourceFile->getClass()->setNamespaceName($responseNamespace); if (!$extendedClass) { $resourceFile->getClass()->setExtendedClass(SoapGenerator::ABSTRACT_RESPONSE_ALIAS)->addUse("{$namespace}\\{$soapNamespace}\\AbstractResult", SoapGenerator::ABSTRACT_RESPONSE_ALIAS); } } else { $type = $structureNamespacePart; $resourceFile->getClass()->setNamespaceName($structureNamespace); } $resourceFile->setFilename("{$sourceDirectory}/{$soapNamespace}/{$type}/{$resourceFile->getClass()->getName()}.php"); $resourceFile->write(); $classmap[$resourceFile->getClass()->getName()] = $resourceFile->getClass()->getNamespaceName() . '\\' . $resourceFile->getClass()->getName(); } foreach (glob("{$commonResourceDirectory}/*.php") as $fileName) { $className = basename($fileName, ".php"); $classmap[$className] = "{$commonResourceNamespace}\\{$className}"; } $classmapValueGenerator = new ValueGenerator($classmap); $classmapFileGenerator = new FileGenerator(); $classmapFileGenerator->setBody('return ' . $classmapValueGenerator->generate() . ';'); $classmapFileGenerator->setFilename("{$sourceDirectory}/{$soapNamespace}/classmap.php"); $classmapFileGenerator->write(); passthru('php ' . __DIR__ . '/../vendor/fabpot/php-cs-fixer/php-cs-fixer fix ' . __DIR__ . '/../src/CallFire/Api/Soap/ --level=all');