protected function buildHydrator($product, $direction) { $this->assertOptionsValid(); $config = $this->options->getConfig(); $class = $this->options->getClass(); $hydrator = new ClassMethods(); if (!isset($config[$this->options->getClass()][$product])) { return $hydrator; } $tmp = new Config(array()); if (isset($config[$class]['*'])) { $tmp = new Config($config[$class]['*']); } if (isset($config[$class][$product])) { $productConfig = new Config($config[$class][$product]); $tmp = $productConfig->merge($tmp); } $config = $tmp['shared']; if (isset($tmp[$direction])) { $config->merge($tmp[$direction]); } $config = $config->toArray(); if (!empty($config['map'])) { $hydrator->setNamingStrategy(new ArrayMapNamingStrategy($config['map'])); } if (!empty($config['strategy'])) { foreach ($config['strategy'] as $name => $strategyCallback) { $hydrator->addStrategy($name, $strategyCallback()); } } if (!empty($config['options'])) { $this->options->setFromArray($config['options']); } return $hydrator; }
protected function _getConfig() { $config = new Config(include 'config/module.config.global.php'); if (file_exists('config/module.config.local.php')) { $config->merge(new Config(include 'config/module.config.local.php')); } return $config['jvandemo_ogone']; }
/** * Sets configuration for the command, allows to override config in runtime * * @param Config $config * @param bool $merge */ public function setConfig(Config $config, $merge = true) { if ($this->config && $merge) { $this->config->merge($config); } else { $this->config = $config; } }
/** * Обновить запись. * Метод PUT для RESTfull. */ public function update($id, $data) { $result = new JsonModel(); $lincutConfigPath = $_SERVER["DOCUMENT_ROOT"] . "/lincut.config.php"; // Создаем в памяти новый конфигурационный файл с новыми настройками $lincutConfigNew = new Config(array(), true); $lincutConfigNew->lincut = array(); $lincutConfigNew->lincut->wkhtmltopdf = array(); $lincutConfigNew->lincut->restriction = array(); if (array_key_exists("wkhtmltopdf_path", $data)) { $lincutConfigNew->lincut->wkhtmltopdf->path = $data["wkhtmltopdf_path"]; } if (array_key_exists("restriction_mode", $data)) { $lincutConfigNew->lincut->restriction->mode = $data["restriction_mode"]; } if (array_key_exists("restriction_up_time", $data)) { $lincutConfigNew->lincut->restriction->uptime = $data["restriction_up_time"]; } if (array_key_exists("restriction_up_count", $data)) { $lincutConfigNew->lincut->restriction->upcount = $data["restriction_up_count"]; } if (array_key_exists("saw", $data)) { $lincutConfigNew->lincut->saw = $data["saw"]; } if (array_key_exists("waste", $data)) { $lincutConfigNew->lincut->waste = $data["waste"]; } $dbwcad = "db/wcad"; $lincutConfigNew->db = array(); $lincutConfigNew->db->adapters = array(); $lincutConfigNew->db->adapters->{$dbwcad} = array(); if (array_key_exists("db_wcad_servername", $data)) { $lincutConfigNew->db->adapters->{$dbwcad}->servername = $data["db_wcad_servername"]; } if (array_key_exists("db_wcad_database", $data)) { $lincutConfigNew->db->adapters->{$dbwcad}->database = $data["db_wcad_database"]; } if (array_key_exists("db_wcad_username", $data)) { $lincutConfigNew->db->adapters->{$dbwcad}->username = $data["db_wcad_username"]; } if (array_key_exists("db_wcad_password", $data)) { $lincutConfigNew->db->adapters->{$dbwcad}->password = $data["db_wcad_password"]; } // Открываем существующий файл настроек, если он имеется в наличии $lincutConfig = array(); if (is_file($lincutConfigPath)) { $lincutConfig = \Zend\Config\Factory::fromFile($lincutConfigPath); } $lincutConfig = new Config($lincutConfig, true); $lincutConfig->merge($lincutConfigNew); // Сохраняем настройки $writer = new \Zend\Config\Writer\PhpArray(); $writer->toFile($lincutConfigPath, $lincutConfig); // Возвращаем результат операции $result->success = true; return $result; }
/** * @inheritDoc */ public function collect($handle, $area = null) { $areas = [LayoutUpdaterInterface::AREA_GLOBAL, $area]; $structure = new Config([], true); foreach ($areas as $area) { $config = isset($this->config[$area][$handle]) ? (array) $this->config[$area][$handle] : []; $structure->merge(new Config($config, true)); } return $structure; }
/** * Merges the app config with the siteaccess config */ public function init() { // Add siteaccess specific config $configHandler = new Config($this->serviceManager->get('config')); $configHandler->merge($this->addConfig()); $this->serviceManager->setAllowOverride(true); $this->serviceManager->setService('config', $configHandler->toArray()); $this->serviceManager->setAllowOverride(false); // not needed I think #$this->baseXMSServices->setService( 'siteaccess', $this ); }
/** * @return DocumentManager */ public function getDocumentManager() { $factory = new DocumentManagerFactory(); $sm = Bootstrap::getServiceManager(); $sm->setAllowOverride(true); $config = $sm->get('Config'); $c = new Config(['eoko' => ['odm' => ['hydrator' => ['class' => 'Zend\\Stdlib\\Hydrator\\ClassMethods', 'strategies' => ['Eoko\\ODM\\Metadata\\Annotation\\DateTime' => new DateTimeFormatterStrategy()]]]]]); $c->merge(new Config($config)); $sm->setService('Config', $c->toArray()); return $factory->createService($sm); }
/** * Get result from cache or read from php file * * @param string $file path to file and filename * @param string $key template file ident * @param ServiceLocatorInterface $sl */ protected function getFileAsConfig($file, $key, $sl) { $cache = $sl->get(static::CONTENTINUM_CACHE); if (!($result = $cache->getItem($key))) { $result = new Config(include $file); if (is_file(CON_ROOT_PATH . '/data/opt/customer.config.php')) { $result->merge(new Config(include CON_ROOT_PATH . '/data/opt/customer.config.php')); } $cache->setItem($key, $result); } return $result; }
/** * @param string $handle */ private function fetchHandle($handle) { foreach ($this->collectors->getIterator() as $collector) { $tempStructure = $collector->collect($handle, $this->getArea()); if ($includes = $tempStructure->get(self::INSTRUCTION_INCLUDE)) { foreach ($includes as $include) { $this->fetchHandle($include); } } $this->layoutStructure->merge($tempStructure); } }
public static function setupConfig(Container $container) { $container->add('config', function () { $DS = DIRECTORY_SEPARATOR; $confPath = ROOT . $DS . 'conf' . $DS; $reader = new Ini(); $config = new Config($reader->fromFile($confPath . 'default.ini')); if (file_exists($confPath . 'local.ini')) { $config->merge(new Config($reader->fromFile($confPath . 'local.ini'))); } return $config; }, true); }
/** * Gets the config for given command key * * @param string $commandKey * @return Config */ protected function getCommandConfig($commandKey) { if (isset($this->configsPerCommandKey[$commandKey])) { return $this->configsPerCommandKey[$commandKey]; } $config = new Config($this->config->get('default')->toArray(), true); if ($this->config->__isset($commandKey)) { $commandConfig = $this->config->get($commandKey); $config->merge($commandConfig); } $this->configsPerCommandKey[$commandKey] = $config; return $config; }
private function generateConfigFile(Config $new_config) { $config_file = 'config/autoload/local.php'; // If there is a config file at that path, so merge the configuration to it. $config = array(); if (file_exists($config_file)) { $config = (include $config_file); } $reader = new Config($config); $reader->merge($new_config); $writer = new \Zend\Config\Writer\PhpArray(); $writer->toFile($config_file, $reader); }
public function init(ServiceLocatorInterface $serviceLocator) { $application = $serviceLocator->get('application'); // Add siteaccess specific config $configHandler = new Config($application->getConfig()); $configHandler->merge($this->addConfig()); //TODO: avoid config in context of the siteaccess $this->config = $configHandler->toArray(); $application->getServiceManager()->setService('accumulator', new Accumulator()); $application->getServiceManager()->setFactory('xmldb', 'BaseXMS\\BaseXFactory'); //TODO: remove all references to baseXMSServices $this->baseXMSServices = $application->getServiceManager(); // not needed I think #$this->baseXMSServices->setService( 'siteaccess', $this ); }
public function getConfig() { $config = new Config(array()); if (is_dir(__DIR__ . '/config')) { $iterator = new \RegexIterator(new \DirectoryIterator(__DIR__ . '/config'), '#\\.config\\.php$#i'); foreach ($iterator as $file) { /** @var $file \DirectoryIterator */ if ($file->isReadable()) { $subConf = new Config(include $file->getRealPath()); $config->merge($subConf); } } } return $config; }
/** * @throws \ErrorException * * @return array */ public function getNavigation() { try { $navigationDefinition = Factory::fromFile($this->rootNavigationFile, true); } catch (\Exception $e) { $navigationDefinition = new Config([]); } foreach ($this->navigationSchemaFinder->getSchemaFiles() as $moduleNavigationFile) { if (!file_exists($moduleNavigationFile->getPathname())) { throw new ErrorException('Navigation-File does not exist: ' . $moduleNavigationFile); } $configFromFile = Factory::fromFile($moduleNavigationFile->getPathname(), true); $navigationDefinition->merge($configFromFile); } return $navigationDefinition->toArray(); }
/** * Get result from cache or read from php file * * @param string $file path to file and filename * @param string $key template file ident * @param ServiceLocatorInterface $sl */ protected function getFileAsConfig($file, $key, $sl) { $cache = $sl->get(static::CONTENTINUM_CACHE); if (!($result = $cache->getItem($key))) { $i = 1; foreach ($file as $singleFile) { if (1 === $i) { $result = new Config(include $singleFile); } else { $result->merge(new Config(include $singleFile)); } $i++; } $cache->setItem($key, $result); } return $result; }
/** * Get result from cache or read from php file * * @param string $file path to file and filename * @param string $key template file ident * @param ServiceLocatorInterface $sl */ protected function getFileAsConfig($dir, $key, $sl) { $cache = $sl->get(static::CONTENTINUM_CACHE); if (!($result = $cache->getItem($key))) { $i = 1; foreach (scandir($dir) as $file) { if ('.' != $file && '..' != $file) { if (1 === $i) { $result = new Config(include $dir . DS . $file); } else { $result->merge(new Config(include $dir . DS . $file)); } $i++; } } $cache->setItem($key, $result); } return $result; }
/** * @inheritDoc */ public function collect($handle, $area = null) { $globPaths = $this->getGlobPaths($handle, $area); $tempStructure = new Config([], true); foreach ($globPaths as $globPath) { try { $configFiles = Glob::glob($globPath, Glob::GLOB_BRACE); } catch (RuntimeException $e) { // @codeCoverageIgnoreStart continue; // @codeCoverageIgnoreEnd } foreach ($configFiles as $configFile) { $config = ConfigFactory::fromFile($configFile, true); $tempStructure->merge($config); } } return $tempStructure; }
/** * Retrieve the config of sphinxsearch node * * @param string|null $file * @return Config */ protected function getConfig($file = null) { // Config $appConfig = $this->getServiceLocator()->get('Config'); if (!isset($appConfig['sphinxsearch'])) { throw new \InvalidArgumentException('Config not found with name: "sphinxsearch"'); } else { $config = new Config($appConfig['sphinxsearch'], true); // defaults if (!is_null($file)) { $fileConfig = Factory::fromFile($file, true); if (!isset($fileConfig['sphinxsearch'])) { throw new \InvalidArgumentException('Config not found with name: "sphinxsearch"'); } $config->merge($fileConfig['sphinxsearch']); } } return $config; }
/** * * @param string $handle */ protected function fetchHandle($handle) { $globPaths = $this->getGlobPaths($handle); foreach ($globPaths as $globPath) { try { $configFiles = Glob::glob($globPath, Glob::GLOB_BRACE); } catch (RuntimeException $e) { continue; } foreach ($configFiles as $configFile) { $config = ConfigFactory::fromFile($configFile, true); if ($includeHandles = $config->get(LayoutUpdaterInterface::INSTRUCTION_INCLUDE)) { foreach ($includeHandles as $includeHandle) { $this->fetchHandle($includeHandle); } } $this->layoutStructure->merge($config); } } }
/** * @param string $key * @return Config * @throws Exception */ public static function get($key) { $instance = self::getInstance(); if ($instance->offsetExists($key)) { return $instance->offsetGet($key); } $baseConfigFile = self::$directory . '/' . $key . '.php'; $environmentConfigFile = self::$directory . '/' . $key . '.' . self::$environment . '.php'; if (!file_exists($baseConfigFile)) { throw new Exception("missing configuration for key {$key}"); } /** @noinspection PhpIncludeInspection */ $config = new Config(include $baseConfigFile); // optional environment configuration if (!empty(self::$environment) && file_exists($environmentConfigFile)) { /** @noinspection PhpIncludeInspection */ $config->merge(new Config(include $environmentConfigFile)); } $instance->offsetSet($key, $config); return $config; }
protected function merge(array $global, array $local) { if (!$local) { return $global; } $global = new Config($global); $local = new Config($local); $global->merge($local); return $global->toArray(); }
/** * @depends testMerge * @link http://framework.zend.com/issues/browse/ZF2-186 */ public function testZF2_186_mergeReplacingUnnamedConfigSettings() { $arrayA = array('flag' => true, 'text' => 'foo', 'list' => array('a', 'b', 'c'), 'aSpecific' => 12); $arrayB = array('flag' => false, 'text' => 'bar', 'list' => array('d', 'e'), 'bSpecific' => 100); $mergeResult = array('flag' => false, 'text' => 'bar', 'list' => array('a', 'b', 'c', 'd', 'e'), 'aSpecific' => 12, 'bSpecific' => 100); $configA = new Config($arrayA); $configB = new Config($arrayB); $configA->merge($configB); // merge B onto A $this->assertEquals($mergeResult, $configA->toArray()); }
protected function getOpenGraphData() { if (!empty($this->openGraphData)) { return $this->openGraphData; } $data = new Config($this->getDefaults()); $page = $this->getPage(); // CMS page if ($page->getPageId()) { /** @var \WShafer\OpenGraph\Repository\OpenGraphRepository $repo */ $repo = $this->entityManager->getRepository('WShafer\\OpenGraph\\Entity\\OpenGraph'); $savedData = new Config($repo->getOpenGraphAsArrayByPage($page)); $data->merge($savedData); } $this->openGraphData = $data->toArray(); return $this->openGraphData; }
/** * Initialize config object, load it from setup files, merge defaults. * * @return Config */ private static function initialize() { $config = new Config(self::getDefaults(), true); $config->merge(new Config(self::loadConfigFile(APP_SETUP_FILE, $migrate))); if ($migrate) { // save config in new format self::saveConfig(APP_SETUP_FILE, $config); } // some subtrees are saved to different files $extra_configs = array('ldap' => APP_CONFIG_PATH . '/ldap.php'); foreach ($extra_configs as $section => $filename) { if (!file_exists($filename)) { continue; } $subconfig = self::loadConfigFile($filename, $migrate); if ($subconfig) { if ($migrate) { // save config in new format self::saveConfig($filename, new Config($subconfig)); } $config->merge(new Config(array($section => $subconfig))); } } return $config; }
<?php use DI\Container; use DI\ContainerBuilder; use Zend\Config\Config; require_once __DIR__ . '/../vendor/autoload.php'; /** * Set up the application in an anonymous function to avoid defining global variables * @return Container */ return call_user_func(function () { $config = new Config(require __DIR__ . '/../config/global.php'); if (file_exists(__DIR__ . '/../config/local.php')) { $temp = new Config(require __DIR__ . '/../config/local.php'); $config->merge($temp); unset($temp); } $builder = new ContainerBuilder(); $builder->addDefinitions(array('config' => $config)); $builder->addDefinitions($config['factories']->toArray()); return $builder->build(); });
/** * Test Bootstrapper * * @copyright Copyright (c) 2012 WebPT, INC */ date_default_timezone_set('UTC'); error_reporting(E_ALL | E_STRICT); defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(__DIR__ . '/../..')); chdir(APPLICATION_PATH); require_once __DIR__ . "/../../vendor/autoload.php"; // special import for the module class as it doesn't appear to namespace structure require_once __DIR__ . '/../../Module.php'; use EMRCore\Config\Application as ApplicationConfig; use Zend\Config\Config as ZendConfig; use Zend\Config\Processor\Token; // Core global config. $moduleConfig = new ZendConfig(include __DIR__ . '/../../vendor/WebPT/EMRCore/src/EMRCore/Config/config/global.php', true); // Module config. $module = new DeskModule\Module(); $moduleConfig->merge(new ZendConfig($module->getConfig())); // Integration global config. $moduleConfig->merge(new ZendConfig(include __DIR__ . '/config/global.php')); // Integration local config. if (file_exists(__DIR__ . '/config/local.php') == true) { $localTestConfig = new ZendConfig(include __DIR__ . '/config/local.php', true); $moduleConfig->merge($localTestConfig); } $processor = new Token($moduleConfig->get('tokens')); $processor->process($moduleConfig); ApplicationConfig::getInstance()->setConfiguration($moduleConfig->toArray(), false);
/** * @group ZF-3575 * */ public function testMergeHonoursAllowModificationsFlagAtAllLevels() { $config = new Config(array('key' => array('nested' => 'yes'), 'key2' => 'yes'), false); $config2 = new Config(array(), true); $config2->merge($config); try { $config2->key2 = 'no'; } catch (\Zend\Config\Exception\RuntimeException $e) { $this->fail('Unexpected exception at top level has been raised: ' . $e->getMessage()); } $this->assertEquals('no', $config2->key2); try { $config2->key->nested = 'no'; } catch (\Zend\Config\Exception\RuntimeException $e) { $this->fail('Unexpected exception on nested object has been raised: ' . $e->getMessage()); } $this->assertEquals('no', $config2->key->nested); }