private function persist() { $this->incoming['accounts'] = array_values($this->incoming['accounts']); $this->outgoing['servers'] = array_values($this->outgoing['servers']); $writer = new PhpArray(); $writer->toFile(self::PATH, [self::KEY_INCOMING => $this->incoming, self::KEY_OUTGOING => $this->outgoing]); }
public function setVersions(array $versions) { $writer = new Config\Writer\PhpArray(); $writer->setUseBracketArraySyntax(true); $writer->toFile($this->_config['path_to_file_versions'], new Config\Config($versions)); @chmod($this->_config['path_to_file_versions'], 0666); }
public function getServiceConfig() { return array('factories' => array('ZF\\Configuration\\ConfigWriter' => function ($services) { $useShortArray = false; if ($services->has('Config')) { $config = $services->get('Config'); if (isset($config['zf-configuration']['enable_short_array'])) { $useShortArray = (bool) $config['zf-configuration']['enable_short_array']; } } $writer = new PhpArray(); if ($useShortArray && version_compare(PHP_VERSION, '5.4.0', '>=')) { $writer->setUseBracketArraySyntax(true); } return $writer; }, 'ZF\\Configuration\\ConfigResource' => function ($services) { $config = array(); $file = 'config/autoload/development.php'; if ($services->has('Config')) { $config = $services->get('Config'); if (isset($config['zf-configuration']) && isset($config['zf-configuration']['config_file'])) { $file = $config['zf-configuration']['config_file']; } } $writer = $services->get('ZF\\Configuration\\ConfigWriter'); return new ConfigResource($config, $file, $writer); }, 'ZF\\Configuration\\ConfigResourceFactory' => function ($services) { $modules = $services->get('ZF\\Configuration\\ModuleUtils'); $writer = $services->get('ZF\\Configuration\\ConfigWriter'); return new ResourceFactory($modules, $writer); }, 'ZF\\Configuration\\ModuleUtils' => function ($services) { $modules = $services->get('ModuleManager'); return new ModuleUtils($modules); })); }
public function flush() { $writer = new PhpArray(); $writer->toFile(self::PATH, [self::KEY => $this->config]); $this->cacheManager->clearCache('module-classmap'); $this->cacheManager->clearCache('module-config'); }
/** * @param ProgressAdapter|null $progressAdapter */ public function updateAddressFormats(ProgressAdapter $progressAdapter = null) { $localeDataUri = $this->options->getLocaleDataUri(); $dataPath = $this->options->getDataPath(); $locales = json_decode($this->httpClient->setUri($localeDataUri)->send()->getContent()); foreach (scandir($dataPath) as $file) { if (fnmatch('*.json', $file)) { unlink($dataPath . '/' . $file); } } $countryCodes = isset($locales->countries) ? explode('~', $locales->countries) : []; $countryCodes[] = 'ZZ'; if ($progressAdapter !== null) { $progressBar = new ProgressBar($progressAdapter, 0, count($countryCodes)); } foreach ($countryCodes as $countryCode) { file_put_contents($dataPath . '/' . $countryCode . '.json', $this->httpClient->setUri($localeDataUri . '/' . $countryCode)->send()->getContent()); if (isset($progressBar)) { $progressBar->next(); } } if (isset($progressBar)) { $progressBar->finish(); } // We clearly don't want the "ZZ" in the array! array_pop($countryCodes); $writer = new PhpArrayWriter(); $writer->setUseBracketArraySyntax(true); $writer->toFile($this->options->getCountryCodesPath(), $countryCodes, false); }
/** * @return PhpArray */ private function getWriter() { if (is_null($this->zendWriter)) { $this->zendWriter = new PhpArray(); $this->zendWriter->setUseBracketArraySyntax(true); } return $this->zendWriter; }
protected function writeConfig() { $writer = new PhpArray(); $writer->toFile('data/rcm/config.php', $this->config, true); chmod('data/rcm/config.php', 0666); if (extension_loaded('Zend OPcache')) { opcache_reset(); } }
protected function generateModuleConfig() { $oModuleConfig = new PhpArray(); $aModuleConfig = array('controllers' => array('invokables' => array($this->getNamespace() . '\\Controller\\' . $this->getNamespace() => $this->getNamespace() . '\\Controller\\' . $this->getNamespace() . 'Controller')), 'router' => array('routes' => array(strtolower($this->getNamespace()) => array('type' => 'segment', 'options' => array('route' => '/' . strtolower($this->getNamespace()) . '[/:action][/:id]', 'constraints' => array('action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[0-9]+'), 'defaults' => array('controller' => $this->getNamespace() . '\\Controller\\' . $this->getNamespace(), 'action' => 'index'))))), 'view_manager' => array('template_path_stack' => array(strtolower($this->getNamespace()) => 'module/' . $this->getNamespace() . '/view')), 'doctrine' => array('driver' => array($this->getNamespace() . '_driver' => array('class' => 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver', 'cache' => 'array', 'paths' => array('__DIR__ . /../src/' . $this->getNamespace() . '/Entity')), 'orm_default' => array('drivers' => array($this->getNamespace() . '\\Entity' => $this->getNamespace() . '_driver'))))); $fileName = 'module/' . $this->getNamespace() . '/config/module.config.php'; if (!is_dir(dirname($fileName))) { mkdir(dirname($fileName), 0777); } $oModuleConfig->toFile($fileName, $aModuleConfig); }
/** * @param $moduleName * * @return bool */ private function updateApplicationConfig($moduleName) { $path = new PathBuilder(); $path = $path->addPart('config')->addPart('application.config.global.php')->getPath(); $data = (include $path); $data['modules'][] = $moduleName; $writer = new PhpArray(); $writer->setUseBracketArraySyntax(true); file_put_contents($path, $writer->toString($data)); return true; }
/** * Create and return a PhpArray config writer. * * @param ContainerInterface $container * @return PhpArray */ public function __invoke(ContainerInterface $container) { $writer = new PhpArray(); if ($this->discoverConfigFlag($container, 'enable_short_array')) { $writer->setUseBracketArraySyntax(true); } if ($this->discoverConfigFlag($container, 'class_name_scalars')) { $writer->setUseClassNameScalars(true); } return $writer; }
/** * Generate/update mapping * @param ArrayObject $spec */ public function create(ArrayObject $spec) { $filePath = $this->getConfig('path') . self::MAPPER_NAME; $configArray = new ArrayObject(); foreach ($spec['entities'] as $entity) { if (isset($entity['entity'])) { $configArray[$entity['entity']] = $entity; unset($entity['entity']); } } $writer = new PhpArray(); $writer->setUseBracketArraySyntax(true); $writer->toFile($filePath, $configArray); }
/** * @return array */ public function indexAction() { /* @var $form Form */ $form = $this->getService('FormElementManager')->get($this->getFormName()); $prg = $this->prg(); $config = $this->getService('config'); $settings = isset($config[$this->getConfigKey()]) ? $config[$this->getConfigKey()] : []; if ($prg instanceof Response) { return $prg; } elseif (false === $prg) { $defaults = $settings; foreach ($settings as $key => $value) { // this needs moving to the form to set defaults there. if ($form->has($key) && $form->get($key) instanceof Fieldset) { if (!array_key_exists($key, $defaults)) { $defaults[$key] = $form->get($key)->getObject()->toArray(); } else { $defaults[$key] = ArrayUtils::merge($form->get($key)->getObject()->toArray(), $defaults[$key]); } } } $form->setData($defaults); return ['form' => $form]; } $form->setData($prg); if ($form->isValid()) { $arrayOrObject = $form->getData(); if (is_array($arrayOrObject)) { unset($arrayOrObject['button-submit']); } if ($arrayOrObject instanceof AbstractOptions) { $arrayOrObject = $arrayOrObject->toArray(); } $filter = new UnderscoreToDash(); $fileName = $filter->filter($this->getConfigKey()); $config = new PhpArray(); $config->setUseBracketArraySyntax(true); $config->toFile('./config/autoload/' . $fileName . '.local.php', [$this->getConfigKey() => $arrayOrObject]); $appConfig = $this->getService('Application\\Config'); // delete cached config. if (true === $appConfig['module_listener_options']['config_cache_enabled']) { $configCache = $appConfig['module_listener_options']['cache_dir'] . '/module-config-cache.' . $appConfig['module_listener_options']['config_cache_key'] . '.php'; if (file_exists($configCache)) { unlink($configCache); } } $this->flashMessenger()->addSuccessMessage('Settings have been updated!'); } return ['form' => $form]; }
public function reinstall($config) { $adapter = new Adapter($config); $adapter->createStatement('DROP DATABASE IF EXISTS `' . $config['database'] . '`')->execute(); $config_file = 'config/autoload/local.php'; $old_config = array(); if (file_exists($config_file)) { $old_config = (include $config_file); unset($old_config['db']); unlink($config_file); $writer = new ConfigWriter(); $writer->toFile($config_file, new Config($old_config)); } $this->install($config); }
public function write($dottedName, $value) { $getset = function ($getset, $name, $value, &$array) { $n = array_shift($name); if (count($name) > 0) { $array[$n] = array(); $newArray =& $array[$n]; $getset($getset, $name, $value, $newArray); } else { $array[$n] = $value; } }; $newNestedArray = array(); $getset($getset, explode('.', $dottedName), $value, $newNestedArray); $newFullConfig = ArrayUtils::merge($this->config, $newNestedArray); $phpArray = new PhpArray(); $phpArray->toFile($this->configPath, $newFullConfig); }
/** * * @param array $params * @param string $posts */ public function processRequest(array $params = null, $posts = null) { try { if (isset($posts['confkey']) && isset($posts['confval'])) { $confkey = $posts['confkey']; $config = new Config(include CON_ROOT_PATH . '/' . $this->configfile, true); $config->contentinum_config->{$confkey} = $posts['confval']; $write = new PhpArray(); $write->toFile(CON_ROOT_PATH . '/' . $this->configfile, $config); if (isset($posts['cachekey'])) { $this->emptyAppCache(); } return array('success' => 'success'); } else { return array('error' => 'miss_parameter'); } } catch (\Exception $e) { return array('error' => $e->getMessage()); } }
/** * * @param array $params * @param string $posts */ public function processRequest(array $params = null, $posts = null) { try { if (isset($posts['cachekey']) && isset($posts['status'])) { $cachekey = $posts['cachekey']; $config = new Config(include CON_ROOT_PATH . '/' . $this->configfile, true); if ('contentinum_navigation_cache' === $cachekey) { if ('off' === $posts['status']) { $config->contentinum_config->contentinum_navigation_cache = true; } else { $config->contentinum_config->contentinum_navigation_cache = false; } $trees = $this->fetchAll("SELECT id FROM web_navigations WHERE (menue = 'std' OR menue = 'helper');"); $cache = $this->getSl()->get(static::CONTENTINUM_CACHE); foreach ($trees as $tree) { if ($cache->hasItem('navigation' . $tree['id'])) { $cache->removeItem('navigation' . $tree['id']); } } } else { if ('off' === $posts['status']) { $config->contentinum_config->db_cache_keys->{$cachekey}->savecache = true; } else { $config->contentinum_config->db_cache_keys->{$cachekey}->savecache = false; } $this->emptyCache($cachekey); } $write = new PhpArray(); $write->toFile(CON_ROOT_PATH . '/' . $this->configfile, $config); return array('success' => 'success'); } else { return array('error' => 'miss parameter'); } } catch (\Exception $e) { return array('error' => $e->getMessage()); } }
<?php use Zend\Config\Factory; use Zend\Config\Writer\PhpArray; $env = getenv('APP_ENV') ?: 'dev'; $mergedConfigFile = __DIR__ . '/../data/cache/config_cache.php'; // If in production and merged config exists, return it if ($env === 'pro' && is_file($mergedConfigFile)) { return include $mergedConfigFile; } // Merge configuration files $mergedConfig = Factory::fromFiles(glob(__DIR__ . '/autoload/{,*.}{global,local}.php', GLOB_BRACE)); // If in production, cache merged config if ($env === 'pro') { $writer = new PhpArray(); $writer->toFile($mergedConfigFile, $mergedConfig); } // Finally, Return the merged configuration return $mergedConfig;
public function testDeleteNonexistentKeyShouldDoNothing() { $config = []; $writer = new PhpArray(); $writer->toFile($this->file, $config); // Ensure the writer has written to the file! $this->assertEquals($config, include $this->file); // Create config resource, and delete a key $configResource = new ConfigResource($config, $this->file, $writer); $test = $configResource->deleteKey('sub.sub2.sub3'); // Verify what was returned was what we expected $expected = []; $this->assertEquals($expected, $test); // Verify the file contains what we expect $test = (include $this->file); $this->assertEquals($expected, $test); }
private function saveConfig($filename, $config) { $writer = new Writer(); $writer->toFile($filename, $config); opcache_invalidate($filename); }
/** * Save model definition * * @throws Exception\ModelFileNotWritableException * @param array $models_definition * @return DriverInterface */ protected function saveModelsDefinition(array $models_definition) { $file = $this->getModelsConfigFile(); if (file_exists($file) && !is_writable($file)) { throw new Exception\ModelFileNotWritableException(__METHOD__ . "Model configuration file '{$file}' cannot be overwritten, not writable."); } //$config = new Config($models_defintion, true); $writer = new Writer\PhpArray(); $models_definition['normalist'] = array('model_version' => Metadata\NormalistModels::VERSION); $writer->toFile($file, $models_definition, $exclusiveLock = true); $perms = $this->params['permissions']; if ($perms != '') { if (decoct(octdec($perms)) == $perms) { $perms = octdec($perms); } chmod($file, $perms); } return $this; }
/** * Interactive database setup. * WILL OUTPUT VIA CONSOLE! * * @param boolean $overwrite Overwrite existing config * @return string */ public function setup($overwrite = false) { /** * Output console usage */ if (!$this->console) { throw new \RuntimeException('You can only use this action from a console!'); } $this->console->writeLine("ZF2 Phinx Module - Interactive Setup", self::GREEN); /** * Check for existing config */ $zfConfig = $this->config['phinx-module']['zf2-config']; $phinxConfig = $this->config['phinx-module']['phinx-config']; if (!$overwrite && (file_exists($zfConfig) || file_exists($phinxConfig))) { if (file_exists($zfConfig) && !file_exists($phinxConfig)) { $this->sync(); $this->console->writeLine("ZF2 Config found but Phinx config missing => Config Synced."); } else { $this->console->writeLine("Existing config file(s) found, unable to continue!", self::LIGHT_RED); $this->console->writeLine("Use the --overwrite flag to replace existing config.", self::LIGHT_RED); } return; } /** * Ask questions */ $loop = true; while ($loop) { $this->console->writeLine("MySQL Database connection details:"); $host = Prompt\Line::prompt("Hostname? [localhost] ", true) ?: 'localhost'; $port = Prompt\Line::prompt("Port? [3306] ", true) ?: 3306; $user = Prompt\Line::prompt("Username? "); $pass = Prompt\Line::prompt("Password? "); $dbname = Prompt\Line::prompt("Database name? "); $loop = !Prompt\Confirm::prompt("Save these details? [y/n]"); } /** * Build config */ $config = new Config(array('db' => array('dsn' => "mysql:host={$host};dbname={$dbname}", 'username' => $user, 'password' => $pass, 'port' => $port))); $writer = new PhpArray(); $writer->toFile($zfConfig, $config); $this->console->writeLine(); $this->console->writeLine("ZF2 Config file written: {$zfConfig}"); /** * Write Phinx config */ $migrations = $this->config['phinx-module']['migrations']; $this->writePhinxConfig('mysql', $host, $user, $pass, $dbname, $port, $migrations); $this->console->writeLine("Phinx Config file written: {$phinxConfig}"); }
private function flush() { $writer = new PhpArray(); $writer->toFile($this->localConfigPath, $this->directories); $this->cacheManager->clearModuleCache(); }
/** * @param $module * @param $config * * @return string */ protected function writeConfig($module, $config) { $file = sprintf('%s/module/%s/config/module.config.php', getcwd(), $module); $writer = new PhpArrayWriter(); // Load local config: $localConfig = array(); if (file_exists($file)) { $localConfig = (include $file); if (!is_array($localConfig)) { $localConfig = array(); } } // Create backup: if ($localConfig) { copy($file, $file . '.backup'); } // Merge with local config $localConfig = ArrayUtils::merge($localConfig, $config); // Write to configuration file $writer->toFile($file, $localConfig); return $file; }
/** * Write configuration * * @param string $filename stub configuration file name * @param array $config * @param bool $exclusiveLock * * @throws \Exception */ public function toFile($filename, $config, $exclusiveLock = true) { $stubDirName = dirname($filename); $separateAllKeys = count($this->separateByKeys) < 1; $renderedStub = ''; foreach ($config as $key => $value) { if (!is_array($value) || !$separateAllKeys && !in_array($key, $this->separateByKeys)) { continue; } // Generate a file name for a configuration key $fileName = $this->keyToFileName($key); // Generate include line for the stub configuration $renderedStub .= " '{$key}' => include __DIR__ . '/{$fileName}',\n"; // Write separated configuration file parent::toFile($stubDirName . '/' . $fileName, $value, $exclusiveLock); // Remove separated configuration from the main configuration unset($config[$key]); } $arraySyntax = array('open' => $this->useBracketArraySyntax ? '[' : 'array(', 'close' => $this->useBracketArraySyntax ? ']' : ')'); $renderedStub = "<?php\n" . "return " . $arraySyntax['open'] . "\n" . $renderedStub . $this->processIndented($config, $arraySyntax) . $arraySyntax['close'] . ";\n"; set_error_handler(function ($error, $message = '') use($filename) { throw new Exception\RuntimeException(sprintf('Error writing to "%s": %s', $filename, $message), $error); }, E_WARNING); $flags = 0; if ($exclusiveLock) { $flags |= LOCK_EX; } try { // for Windows, paths are escaped. $stubDirName = str_replace('\\', '\\\\', $stubDirName); $renderedStub = str_replace("'" . $stubDirName, "__DIR__ . '", $renderedStub); file_put_contents($filename, $renderedStub, $flags); } catch (\Exception $e) { restore_error_handler(); throw $e; } restore_error_handler(); }