/** * 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; }
/** * @param array $configData * @param $configFile * @param boolean $align * * @return bool */ public function updateConfiguration(array $configData, $configFile, $align = false) { // set old file $oldFile = str_replace('.php', '.old', $configFile); // copy to old file if (file_exists($configFile)) { copy($configFile, $oldFile); } // create config array $array = new ValueGenerator(); $array->initEnvironmentConstants(); $array->setValue($configData); $array->setArrayDepth(0); // generate body $body = 'return ' . $array->generate() . ';' . AbstractGenerator::LINE_FEED; // check for alignment if ($align) { // Align "=>" operators to match coding standard preg_match_all('(\\n\\s+([^=]+)=>)', $body, $matches, PREG_SET_ORDER); $maxWidth = 0; foreach ($matches as $match) { $maxWidth = max($maxWidth, strlen($match[1])); } $body = preg_replace('(\\n\\s+([^=]+)=>)e', "'\n \\1' . str_repeat(' ', " . $maxWidth . " - strlen('\\1')) . '=>'", $body); } // create file with file generator $file = new FileGenerator(); $file->setBody($body); // add optional doc block if ($this->flagCreateApiDocs) { $file->setDocBlock(new DocBlockGenerator('Configuration file generated by FrilleZFTool', 'The previous configuration file is stored in ' . $oldFile, array($this->generateSeeTag()))); } // write application configuration if (!file_put_contents($configFile, $file->generate())) { return false; } return true; }