/** * Sets the default route according to the configuration data provided in $config. * Two settings are required: the route prefix (key: routePrefix), * and the controller class-name (key: controllerClass). * * Three optional settings are supported as well: major section (key: majorSection), * minor section (key: minorSection) and request parameters (key: params); * which might be used during the routing process. * * @param Zend_Config $config Configuration data * @param array $dependencyData Data array supplied by the "init_dependencies" event * @throws XenForo_Exception */ public static function setDefaultRoute(Zend_Config $config, array $dependencyData) { $routesPublic = $dependencyData['routesPublic']; if (!$config->routePrefix || !$config->controllerClass) { // Debugging message. No need for phrasing. throw new XenForo_Exception('Missing route-prefix and/or controller class-name.'); } if ($config->readOnly()) { // A read-only object was passed. Arghh! $newConfig = new Zend_Config(array('routeClass' => $routesPublic[$config->routePrefix]['route_class']), true); $config = $newConfig->merge($config); } else { $config->routeClass = $routesPublic[$config->routePrefix]['route_class']; } self::_setCustomRoutePrefixes($config->routePrefix, $routesPublic); $config->setReadOnly(); XenForo_Application::set('customIndex', $config); }
/** * Diesen Merge sollte eigentlich das Zend machen, aber das merged nicht so * wie wir das erwarten. Beispiel: * * Main Config: * bla.blubb[] = x * bla.blubb[] = y * bla.blubb[] = z * * Merge Config: * bla.blubb[] = a * bla.blubb[] = b * * Nach den Config-Section regeln würde man erwarten, dass nach dem mergen nur mehr * a und b drin steht. Tatsächlich merget Zend aber so, dass a, b, z überbleibt. * Zend überschreibt die Werte, was wir nicht wollen, deshalb dieses * händische mergen hier. */ public static function mergeConfigs(Zend_Config $main, Zend_Config $merge) { // check if all keys are of type 'integer' and if so, only use merge config $everyKeyIsInteger = true; foreach ($merge as $key => $item) { if (!is_int($key)) { $everyKeyIsInteger = false; break; } } if ($everyKeyIsInteger) { return $merge; } foreach ($merge as $key => $item) { if (isset($main->{$key})) { if ($item instanceof Zend_Config && $main->{$key} instanceof Zend_Config) { $main->{$key} = Kwf_Config_Web::mergeConfigs($main->{$key}, new Zend_Config($item->toArray(), !$main->readOnly())); } else { $main->{$key} = $item; } } else { if ($item instanceof Zend_Config) { $main->{$key} = new Zend_Config($item->toArray(), !$main->readOnly()); } else { $main->{$key} = $item; } } } return $main; }
/** * @group ZF-4728 * */ public function testSetReadOnlyAppliesToChildren() { $config = new Zend_Config($this->_all, true); $config->setReadOnly(); $this->assertTrue($config->readOnly()); $this->assertTrue($config->one->readOnly(), 'First level children are writable'); $this->assertTrue($config->one->two->readOnly(), 'Second level children are writable'); }
/** * Updates a value in a Zend_Config object. * * @param Zend_Config $config * @param $option Name of option * @param $value New value * @throws Zend_Exception */ public static function setValueInConfig(Zend_Config $config, $option, $value) { if ($config->readOnly()) { Zend_Registry::get('Zend_Log')->err('Zend_Config object is readonly.'); return; } $keys = explode('.', $option); $subconfig = $config; $index = 0; foreach ($keys as $key) { $index++; if (is_null($subconfig->get($key)) && $index < count($keys)) { // create subsection eval('$subconfig->' . $key . ' = array();'); $subconfig = $subconfig->get($key); } else { // set value eval('$subconfig->' . $key . ' = $value;'); } } }