/** * 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; }
/** * Create and add elements to this form * * @param array $formData */ public function createElements(array $formData) { // LdapUserGroupBackendForm requires these factories to provide valid configurations ResourceFactory::setConfig($this->createResourceConfiguration()); UserBackend::setConfig($this->createBackendConfiguration()); $backendForm = new LdapUserGroupBackendForm(); $formData['type'] = 'ldap'; $backendForm->create($formData); $backendForm->getElement('name')->setValue('icingaweb2'); $this->addSubForm($backendForm, 'backend_form'); $backendForm->addElement('hidden', 'resource', array('required' => true, 'value' => $this->resourceConfig['name'], 'decorators' => array('ViewHelper'))); $backendForm->addElement('hidden', 'user_backend', array('required' => true, 'value' => $this->backendConfig['name'], 'decorators' => array('ViewHelper'))); }
/** * Set up the resource factory * * @return $this */ protected function setupResourceFactory() { try { $config = Config::app('resources'); ResourceFactory::setConfig($config); } catch (NotReadableError $e) { Logger::error(new IcingaException('Cannot load resource configuration. An exception was thrown:', $e)); } return $this; }
/** * 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; }