/** * Set the resource configuration to use * * @param array $config * * @return $this */ public function setResourceConfig(array $config) { $resourceConfig = new Config(); $resourceConfig->setSection($config['name'], $config); ResourceFactory::setConfig($resourceConfig); $this->config = $config; return $this; }
/** * Return the user backend configuration as Config object * * @return Config */ protected function createBackendConfiguration() { $config = new Config(); $backendConfig = $this->backendConfig; $backendConfig['resource'] = $this->resourceConfig['name']; $config->setSection($this->backendConfig['name'], $backendConfig); return $config; }
/** * {@inheritdoc} */ public function onSuccess() { $sections = array(); foreach ($this->getValues() as $sectionAndPropertyName => $value) { if ($value === '') { $value = null; // Causes the config writer to unset it } list($section, $property) = explode('_', $sectionAndPropertyName, 2); $sections[$section][$property] = $value; } foreach ($sections as $section => $config) { $this->config->setSection($section, $config); } if ($this->save()) { Notification::success($this->translate('New configuration has successfully been stored')); } else { return false; } }
/** * Update the target with the given data and optionally limit the affected entries by using a filter * * @param string $target * @param array $data * @param Filter $filter * * @throws StatementException In case the operation has failed */ public function update($target, array $data, Filter $filter = null) { $newData = $this->requireStatementColumns($target, $data); $keyColumn = $this->ds->getConfigObject()->getKeyColumn(); if ($filter === null && isset($newData[$keyColumn])) { throw new StatementException(t('Cannot update. Column "%s" holds a section\'s name which must be unique'), $keyColumn); } if ($filter !== null) { $filter = $this->requireFilter($target, $filter); } $newSection = null; foreach (iterator_to_array($this->ds) as $section => $config) { if ($filter !== null && !$filter->matches($config)) { continue; } if ($newSection !== null) { throw new StatementException(t('Cannot update. Column "%s" holds a section\'s name which must be unique'), $keyColumn); } foreach ($newData as $column => $value) { if ($column === $keyColumn) { $newSection = $value; } else { $config->{$column} = $value; } } if ($newSection) { if ($this->ds->hasSection($newSection)) { throw new StatementException(t('Cannot update. Section "%s" does already exist'), $newSection); } $this->ds->removeSection($section)->setSection($newSection, $config); } else { $this->ds->setSection($section, $config); } } try { $this->ds->saveIni(); } catch (Exception $e) { throw new StatementException(t('Failed to update. An error occurred: %s'), $e->getMessage()); } }
/** * @depends testWhetherConfigSetsSingleSections */ public function testWhetherConfigKnowsWhichSectionsItHas() { $config = new Config(); $config->setSection('a'); $this->assertTrue($config->hasSection('a'), 'Config::hasSection does not know anything about its sections'); $this->assertFalse($config->hasSection('b'), 'Config::hasSection does not know anything about its sections'); }
/** * Create and return the user group backend * * @return LdapUserGroupBackend */ protected function createUserGroupBackend() { $resourceConfig = new Config(); $resourceConfig->setSection($this->resourceConfig['name'], $this->resourceConfig); ResourceFactory::setConfig($resourceConfig); $backendConfig = new Config(); $backendConfig->setSection($this->backendConfig['name'], array_merge($this->backendConfig, array('resource' => $this->resourceConfig['name']))); UserBackend::setConfig($backendConfig); if (empty($this->groupConfig)) { $groupConfig = new ConfigObject(array('backend' => $this->backendConfig['backend'], 'resource' => $this->resourceConfig['name'], 'user_backend' => $this->backendConfig['name'])); } else { $groupConfig = new ConfigObject($this->groupConfig); } $backend = UserGroupBackend::create(null, $groupConfig); if (!$backend instanceof Selectable) { throw new NotImplementedError('Unsupported, until #9772 has been resolved'); } return $backend; }