public function testMoveBackend() { $config = Config::fromArray(array('test1' => '', 'test2' => '', 'test3' => '')); $this->getRequestMock()->shouldReceive('getMethod')->andReturn('POST')->shouldReceive('isPost')->andReturn(true)->shouldReceive('getPost')->andReturn(array('backend_newpos' => 'test3|1')); $form = new UserBackendReorderFormProvidingConfigFormWithoutSave(); $form->setIniConfig($config); $form->setTokenDisabled(); $form->setUidDisabled(); $form->handleRequest(); $this->assertEquals(array('test1', 'test3', 'test2'), UserBackendConfigFormWithoutSave::$newConfig->keys(), 'Moving elements with UserBackendReorderForm does not seem to properly work'); }
public function apply() { $config = array(); $config['security'] = $this->data['securityConfig']; try { Config::fromArray($config)->setConfigFile(Config::resolvePath('modules/monitoring/config.ini'))->saveIni(); } catch (Exception $e) { $this->error = $e; return false; } $this->error = false; return true; }
protected function defineInitialAdmin() { $config = array(); $config['admins'] = array('users' => $this->data['adminAccountData']['username'], 'permissions' => '*'); try { Config::fromArray($config)->setConfigFile(Config::resolvePath('roles.ini'))->saveIni(); } catch (Exception $e) { $this->permIniError = $e; return false; } $this->permIniError = false; return true; }
protected function createBackendsIni() { $config = array(); $config[$this->data['backendConfig']['name']] = array('type' => $this->data['backendConfig']['type'], 'resource' => $this->data['resourceConfig']['name']); try { Config::fromArray($config)->setConfigFile(Config::resolvePath('modules/monitoring/backends.ini'))->saveIni(); } catch (Exception $e) { $this->backendIniError = $e; return false; } $this->backendIniError = false; return true; }
/** * Get the configuration of all existing resources, or all resources of the given type * * @param string $type Filter for resource type * * @return Config The resources configuration */ public static function getResourceConfigs($type = null) { self::assertResourcesExist(); if ($type === null) { return self::$resources; } $resources = array(); foreach (self::$resources as $name => $resource) { if ($resource->get('type') === $type) { $resources[$name] = $resource; } } return Config::fromArray($resources); }
public function apply() { $transportConfig = $this->data['transportConfig']; $transportName = $transportConfig['name']; unset($transportConfig['name']); try { Config::fromArray(array($transportName => $transportConfig))->setConfigFile(Config::resolvePath('modules/monitoring/commandtransports.ini'))->saveIni(); } catch (Exception $e) { $this->error = $e; return false; } $this->error = false; return true; }
/** * Render the Zend_Config into a config filestring * * @return string */ public function render() { if (file_exists($this->filename)) { $oldconfig = Config::fromIni($this->filename); $content = trim(file_get_contents($this->filename)); } else { $oldconfig = Config::fromArray(array()); $content = ''; } $doc = IniParser::parseIni($content); $this->diffPropertyUpdates($this->config, $doc); $this->diffPropertyDeletions($oldconfig, $this->config, $doc); $doc = $this->updateSectionOrder($this->config, $doc); return $doc->render(); }
public function apply() { $config = array(); foreach ($this->data['generalConfig'] as $sectionAndPropertyName => $value) { list($section, $property) = explode('_', $sectionAndPropertyName, 2); $config[$section][$property] = $value; } if ($config['global']['config_backend'] === 'db') { $config['global']['config_resource'] = $this->data['resourceName']; } try { Config::fromArray($config)->setConfigFile(Config::resolvePath('config.ini'))->saveIni(); } catch (Exception $e) { $this->error = $e; return false; } $this->error = false; return true; }
protected function createRolesIni() { if (isset($this->data['adminAccountData']['username'])) { $config = array('users' => $this->data['adminAccountData']['username'], 'permissions' => '*'); if ($this->data['backendConfig']['backend'] === 'db') { $config['groups'] = mt('setup', 'Administrators', 'setup.role.name'); } } else { // isset($this->data['adminAccountData']['groupname']) $config = array('groups' => $this->data['adminAccountData']['groupname'], 'permissions' => '*'); } try { Config::fromArray(array(mt('setup', 'Administrators', 'setup.role.name') => $config))->setConfigFile(Config::resolvePath('roles.ini'))->saveIni(); } catch (Exception $e) { $this->permIniError = $e; return false; } $this->permIniError = false; return true; }
public function apply() { $config = array(); foreach ($this->data['generalConfig'] as $sectionAndPropertyName => $value) { list($section, $property) = explode('_', $sectionAndPropertyName); $config[$section][$property] = $value; } $config['preferences']['store'] = $this->data['preferencesStore']; if (isset($this->data['preferencesResource'])) { $config['preferences']['resource'] = $this->data['preferencesResource']; } try { Config::fromArray($config)->setConfigFile(Config::resolvePath('config.ini'))->saveIni(); } catch (Exception $e) { $this->error = $e; return false; } $this->error = false; return true; }
protected function createGroupsIni() { $config = array(); if (isset($this->data['groupConfig'])) { $backendConfig = $this->data['groupConfig']; $backendName = $backendConfig['name']; unset($backendConfig['name']); $config[$backendName] = $backendConfig; } else { $backendConfig = array('backend' => $this->data['backendConfig']['backend'], 'resource' => $this->data['resourceName']); if ($backendConfig['backend'] === 'msldap') { $backendConfig['user_backend'] = $this->data['backendConfig']['name']; } $config[$this->data['backendConfig']['name']] = $backendConfig; } try { Config::fromArray($config)->setConfigFile(Config::resolvePath('groups.ini'))->saveIni(); } catch (Exception $e) { $this->groupIniError = $e; return false; } $this->groupIniError = false; return true; }
public function apply() { $resourceConfig = array(); if (isset($this->data['dbResourceConfig'])) { $dbConfig = $this->data['dbResourceConfig']; $resourceName = $dbConfig['name']; unset($dbConfig['name']); $resourceConfig[$resourceName] = $dbConfig; } if (isset($this->data['ldapResourceConfig'])) { $ldapConfig = $this->data['ldapResourceConfig']; $resourceName = $ldapConfig['name']; unset($ldapConfig['name']); $resourceConfig[$resourceName] = $ldapConfig; } try { Config::fromArray($resourceConfig)->setConfigFile(Config::resolvePath('resources.ini'))->saveIni(); } catch (Exception $e) { $this->error = $e; return false; } $this->error = false; return true; }
public function testExplicitRemove() { $filename = tempnam(sys_get_temp_dir(), 'iw2'); $config = Config::fromArray(array('garbage' => array('foobar' => 'lolcat'))); $iniWriter = new IniWriter($config, $filename); $iniWriter->write(); $section = $config->getSection('garbage'); $section->foobar = null; $iniWriter = new IniWriter($config, $filename); $this->assertNotContains('foobar', $iniWriter->render(), 'IniWriter doesn\'t remove section keys with null values'); unlink($filename); }
/** * Create and return a Config object for this dashboard * * @return Config */ public function getConfig() { $output = array(); foreach ($this->panes as $pane) { if ($pane->isUserWidget()) { $output[$pane->getName()] = $pane->toArray(); } foreach ($pane->getDashlets() as $dashlet) { if ($dashlet->isUserWidget()) { $output[$pane->getName() . '.' . $dashlet->getTitle()] = $dashlet->toArray(); } } } return Config::fromArray($output)->setConfigFile($this->getConfigFile()); }
/** * Move the given user backend up or down in order * * @param string $name The name of the backend to be moved * @param int $position The new (absolute) position of the backend * * @return $this * * @throws InvalidArgumentException In case the backend does not exist */ public function move($name, $position) { if (!$name) { throw new InvalidArgumentException($this->translate('User backend name missing')); } elseif (!$this->config->hasSection($name)) { throw new InvalidArgumentException($this->translate('Unknown user backend provided')); } $backendOrder = $this->config->keys(); array_splice($backendOrder, array_search($name, $backendOrder), 1); array_splice($backendOrder, $position, 0, $name); $newConfig = array(); foreach ($backendOrder as $backendName) { $newConfig[$backendName] = $this->config->getSection($backendName); } $config = Config::fromArray($newConfig); $this->config = $config->setConfigFile($this->config->getConfigFile()); return $this; }
/** * Read the ini file and parse it with ::parseIni() * * @param string $file The ini file to read * * @return Config * @throws NotReadableError When the file cannot be read */ public static function parseIniFile($file) { if (($path = realpath($file)) === false) { throw new NotReadableError('Couldn\'t compute the absolute path of `%s\'', $file); } if (($content = file_get_contents($path)) === false) { throw new NotReadableError('Couldn\'t read the file `%s\'', $path); } return Config::fromArray(self::parseIni($content)->toArray())->setConfigFile($file); }
/** * Move the given user backend up or down in order * * @param string $name The name of the backend to be moved * @param int $position The new (absolute) position of the backend * * @return $this * * @throws NotFoundError In case no backend with the given name is found */ public function move($name, $position) { if (!$this->config->hasSection($name)) { throw new NotFoundError('No user backend called "%s" found', $name); } $backendOrder = $this->config->keys(); array_splice($backendOrder, array_search($name, $backendOrder), 1); array_splice($backendOrder, $position, 0, $name); $newConfig = array(); foreach ($backendOrder as $backendName) { $newConfig[$backendName] = $this->config->getSection($backendName); } $config = Config::fromArray($newConfig); $this->config = $config->setConfigFile($this->config->getConfigFile()); return $this; }
/** * Write the preferences * * @throws NotWritableError In case the INI file cannot be written */ public function write() { Config::fromArray($this->preferences)->saveIni($this->preferencesFile); }
public function testWhetherLinebreaksAreRemoved() { $target = $this->writeConfigToTemporaryFile(''); $writer = new IniWriter(array('config' => Config::fromArray(array('section' => array('foo' => 'linebreak in line', 'linebreak inkey' => 'blarg'))), 'filename' => $target)); $rendered = $writer->render(); $this->assertEquals(count(explode("\n", $rendered)), 4, 'generated config should not contain more than three line breaks'); }
public function testSectionDeleted() { $config = <<<'EOD' [section 1] guarg = "1" [section 2] foo = "1337" foo2 = "baz" foo3 = "nope" foo4 = "bar" [section 3] guard = "2" EOD; $deleted = <<<'EOD' [section 1] guarg = "1" [section 3] guard = "2" EOD; $target = $this->writeConfigToTemporaryFile($config); $writer = new IniWriter(Config::fromArray(array('section 1' => array('guarg' => 1), 'section 3' => array('guard' => 2))), $target); $this->assertEquals(trim($deleted), trim($writer->render()), 'IniWriter does not delete sections properly'); }
/** * @expectedException UnexpectedValueException */ public function testWhetherAnExceptionIsThrownWhenTryingToAccessASectionPropertyOnANonSection() { $config = Config::fromArray(array('a' => 'b')); $config->get('a', 'b'); }