Skip to content

Commit

Permalink
Merge branch 'bugfix/drop-zend-config-7147'
Browse files Browse the repository at this point in the history
fixes #7147
  • Loading branch information
Johannes Meyer committed Nov 18, 2014
2 parents 985df11 + c288a68 commit ed65052
Show file tree
Hide file tree
Showing 75 changed files with 1,008 additions and 684 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -10,3 +10,5 @@ var/log/*

# Exclude symlink you need for packaging
/debian

build/*
11 changes: 2 additions & 9 deletions application/controllers/AuthenticationController.php
Expand Up @@ -33,15 +33,8 @@ class AuthenticationController extends ActionController
*/
public function loginAction()
{
if (@file_exists(Config::$configDir . '/setup.token')) {
try {
$config = Config::app()->toArray();
if (empty($config)) {
$this->redirectNow(Url::fromPath('setup'));
}
} catch (NotReadableError $e) {
// Gets thrown in case of insufficient permission only
}
if (@file_exists(Config::resolvePath('setup.token')) && !@file_exists(Config::resolvePath('config.ini'))) {
$this->redirectNow(Url::fromPath('setup'));
}

$auth = $this->Auth();
Expand Down
14 changes: 7 additions & 7 deletions application/controllers/ConfigController.php
Expand Up @@ -177,10 +177,10 @@ public function editauthenticationbackendAction()
public function removeauthenticationbackendAction()
{
$form = new ConfirmRemovalForm(array(
'onSuccess' => function ($request) {
'onSuccess' => function ($form) {
$configForm = new AuthenticationBackendConfigForm();
$configForm->setIniConfig(Config::app('authentication'));
$authBackend = $request->getQuery('auth_backend');
$authBackend = $form->getRequest()->getQuery('auth_backend');

try {
$configForm->remove($authBackend);
Expand Down Expand Up @@ -212,7 +212,7 @@ public function removeauthenticationbackendAction()
*/
public function resourceAction()
{
$this->view->resources = Config::app('resources', true)->toArray();
$this->view->resources = Config::app('resources', true)->keys();
$this->view->tabs->activate('resources');
}

Expand Down Expand Up @@ -250,10 +250,10 @@ public function editresourceAction()
public function removeresourceAction()
{
$form = new ConfirmRemovalForm(array(
'onSuccess' => function ($request) {
'onSuccess' => function ($form) {
$configForm = new ResourceConfigForm();
$configForm->setIniConfig(Config::app('resources'));
$resource = $request->getQuery('resource');
$resource = $form->getRequest()->getQuery('resource');

try {
$configForm->remove($resource);
Expand All @@ -274,9 +274,9 @@ public function removeresourceAction()

// Check if selected resource is currently used for authentication
$resource = $this->getRequest()->getQuery('resource');
$authConfig = Config::app('authentication')->toArray();
$authConfig = Config::app('authentication');
foreach ($authConfig as $backendName => $config) {
if (array_key_exists('resource', $config) && $config['resource'] === $resource) {
if ($config->get('resource') === $resource) {
$form->addError(sprintf(
$this->translate(
'The resource "%s" is currently in use by the authentication backend "%s". ' .
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/DashboardController.php
Expand Up @@ -37,7 +37,7 @@ private function getDashboard($config = self::DEFAULT_CONFIG)
$dashboard = new Dashboard();
try {
$dashboardConfig = Config::app($config);
if (count($dashboardConfig) === 0) {
if ($dashboardConfig->isEmpty()) {
return null;
}
$dashboard->readConfig($dashboardConfig);
Expand Down Expand Up @@ -93,7 +93,7 @@ public function addurlAction()
);

$configFile = Config::app('dashboard/dashboard')->getConfigFile();
if ($this->writeConfiguration(new Config($dashboard->toArray()), $configFile)) {
if ($this->writeConfiguration(Config::fromArray($dashboard->toArray()), $configFile)) {
$this->redirectNow(Url::fromPath('dashboard', array('pane' => $form->getValue('pane'))));
} else {
$this->render('showConfiguration');
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/ListController.php
Expand Up @@ -5,7 +5,7 @@
use Icinga\Module\Monitoring\Controller;
use Icinga\Web\Url;
use Icinga\Application\Logger;
use Icinga\Application\Config;
use Icinga\Data\ConfigObject;
use Icinga\Protocol\File\FileReader;
use \Zend_Controller_Action_Exception as ActionError;

Expand Down Expand Up @@ -48,7 +48,7 @@ public function applicationlogAction()
. ' - (?<message>.*)$/'; // message

$loggerWriter = Logger::getInstance()->getWriter();
$resource = new FileReader(new Config(array(
$resource = new FileReader(new ConfigObject(array(
'filename' => $loggerWriter->getPath(),
'fields' => $pattern
)));
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/PreferenceController.php
Expand Up @@ -39,8 +39,8 @@ public static function createProvidedTabs()
*/
public function indexAction()
{
$storeConfig = Config::app()->preferences;
if ($storeConfig === null) {
$storeConfig = Config::app()->getSection('preferences');
if ($storeConfig->isEmpty()) {
throw new ConfigurationError(t('You need to configure how to store preferences first.'));
}

Expand Down
4 changes: 2 additions & 2 deletions application/forms/Config/Authentication/DbBackendForm.php
Expand Up @@ -5,8 +5,8 @@
namespace Icinga\Forms\Config\Authentication;

use Exception;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;
use Icinga\Authentication\Backend\DbUserBackend;

Expand Down Expand Up @@ -121,7 +121,7 @@ public static function isValidAuthenticationBackend(Form $form)
/**
* Return the configuration for the chosen resource
*
* @return Config
* @return ConfigObject
*/
public function getResourceConfig()
{
Expand Down
4 changes: 2 additions & 2 deletions application/forms/Config/Authentication/LdapBackendForm.php
Expand Up @@ -5,8 +5,8 @@
namespace Icinga\Forms\Config\Authentication;

use Exception;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;
use Icinga\Exception\AuthenticationException;
use Icinga\Authentication\Backend\LdapUserBackend;
Expand Down Expand Up @@ -156,7 +156,7 @@ public static function isValidAuthenticationBackend(Form $form)
/**
* Return the configuration for the chosen resource
*
* @return Config
* @return ConfigObject
*/
public function getResourceConfig()
{
Expand Down
33 changes: 18 additions & 15 deletions application/forms/Config/AuthenticationBackendConfigForm.php
Expand Up @@ -9,6 +9,7 @@
use Icinga\Web\Notification;
use Icinga\Application\Config;
use Icinga\Application\Platform;
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;
use Icinga\Exception\ConfigurationError;
use Icinga\Forms\Config\Authentication\DbBackendForm;
Expand Down Expand Up @@ -91,12 +92,12 @@ public function add(array $values)
$name = isset($values['name']) ? $values['name'] : '';
if (! $name) {
throw new InvalidArgumentException(t('Authentication backend name missing'));
} elseif ($this->config->get($name) !== null) {
} elseif ($this->config->hasSection($name)) {
throw new InvalidArgumentException(t('Authentication backend already exists'));
}

unset($values['name']);
$this->config->{$name} = $values;
$this->config->setSection($name, $values);
return $this;
}

Expand All @@ -116,18 +117,19 @@ public function edit($name, array $values)
throw new InvalidArgumentException(t('Old authentication backend name missing'));
} elseif (! ($newName = isset($values['name']) ? $values['name'] : '')) {
throw new InvalidArgumentException(t('New authentication backend name missing'));
} elseif (($backendConfig = $this->config->get($name)) === null) {
} elseif (! $this->config->hasSection($name)) {
throw new InvalidArgumentException(t('Unknown authentication backend provided'));
}

$backendConfig = $this->config->getSection($name);
if ($newName !== $name) {
// Only remove the old entry if it has changed as the order gets screwed when editing backend names
unset($this->config->{$name});
$this->config->removeSection($name);
}

unset($values['name']);
$this->config->{$newName} = array_merge($backendConfig->toArray(), $values);
return $this->config->{$newName};
$this->config->setSection($newName, $backendConfig->merge($values));
return $backendConfig;
}

/**
Expand All @@ -143,11 +145,12 @@ public function remove($name)
{
if (! $name) {
throw new InvalidArgumentException(t('Authentication backend name missing'));
} elseif (($backendConfig = $this->config->get($name)) === null) {
} elseif (! $this->config->hasSection($name)) {
throw new InvalidArgumentException(t('Unknown authentication backend provided'));
}

unset($this->config->{$name});
$backendConfig = $this->config->getSection($name);
$this->config->removeSection($name);
return $backendConfig;
}

Expand All @@ -165,7 +168,7 @@ public function move($name, $position)
{
if (! $name) {
throw new InvalidArgumentException(t('Authentication backend name missing'));
} elseif ($this->config->get($name) === null) {
} elseif (! $this->config->hasSection($name)) {
throw new InvalidArgumentException(t('Unknown authentication backend provided'));
}

Expand All @@ -175,10 +178,10 @@ public function move($name, $position)

$newConfig = array();
foreach ($backendOrder as $backendName) {
$newConfig[$backendName] = $this->config->get($backendName);
$newConfig[$backendName] = $this->config->getSection($backendName);
}

$config = new Config($newConfig);
$config = Config::fromArray($newConfig);
$this->config = $config->setConfigFile($this->config->getConfigFile());
return $this;
}
Expand Down Expand Up @@ -235,13 +238,13 @@ public function onRequest()
if ($authBackend !== null) {
if ($authBackend === '') {
throw new ConfigurationError(t('Authentication backend name missing'));
} elseif (false === isset($this->config->{$authBackend})) {
} elseif (! $this->config->hasSection($authBackend)) {
throw new ConfigurationError(t('Unknown authentication backend provided'));
} elseif (false === isset($this->config->{$authBackend}->backend)) {
} elseif ($this->config->getSection($authBackend)->backend === null) {
throw new ConfigurationError(sprintf(t('Backend "%s" has no `backend\' setting'), $authBackend));
}

$configValues = $this->config->{$authBackend}->toArray();
$configValues = $this->config->getSection($authBackend)->toArray();
$configValues['type'] = $configValues['backend'];
$configValues['name'] = $authBackend;
$this->populate($configValues);
Expand Down Expand Up @@ -332,7 +335,7 @@ function ($authBackendCfg) {
/**
* Return the configuration for the chosen resource
*
* @return Config
* @return ConfigObject
*/
public function getResourceConfig()
{
Expand Down
2 changes: 1 addition & 1 deletion application/forms/Config/GeneralConfigForm.php
Expand Up @@ -48,7 +48,7 @@ public function onSuccess()
$sections[$section][$property] = $value;
}
foreach ($sections as $section => $config) {
$this->config->{$section} = $config;
$this->config->setSection($section, $config);
}

if ($this->save()) {
Expand Down
4 changes: 2 additions & 2 deletions application/forms/Config/Resource/DbResourceForm.php
Expand Up @@ -5,8 +5,8 @@
namespace Icinga\Forms\Config\Resource;

use Exception;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;
use Icinga\Application\Platform;

Expand Down Expand Up @@ -129,7 +129,7 @@ public function onSuccess()
public static function isValidResource(Form $form)
{
try {
$resource = ResourceFactory::createResource(new Config($form->getValues()));
$resource = ResourceFactory::createResource(new ConfigObject($form->getValues()));
$resource->getConnection()->getConnection();
} catch (Exception $e) {
$form->addError(t('Connectivity validation failed, connection to the given resource not possible.'));
Expand Down
4 changes: 2 additions & 2 deletions application/forms/Config/Resource/LdapResourceForm.php
Expand Up @@ -5,8 +5,8 @@
namespace Icinga\Forms\Config\Resource;

use Exception;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;

/**
Expand Down Expand Up @@ -110,7 +110,7 @@ public function onSuccess()
public static function isValidResource(Form $form)
{
try {
$resource = ResourceFactory::createResource(new Config($form->getValues()));
$resource = ResourceFactory::createResource(new ConfigObject($form->getValues()));
if (false === $resource->testCredentials(
$form->getElement('bind_dn')->getValue(),
$form->getElement('bind_pw')->getValue()
Expand Down
4 changes: 2 additions & 2 deletions application/forms/Config/Resource/LivestatusResourceForm.php
Expand Up @@ -5,9 +5,9 @@
namespace Icinga\Forms\Config\Resource;

use Exception;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Application\Icinga;
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;

/**
Expand Down Expand Up @@ -73,7 +73,7 @@ public function onSuccess()
public static function isValidResource(Form $form)
{
try {
$resource = ResourceFactory::createResource(new Config($form->getValues()));
$resource = ResourceFactory::createResource(new ConfigObject($form->getValues()));
$resource->connect()->disconnect();
} catch (Exception $e) {
$form->addError(t('Connectivity validation failed, connection to the given resource not possible.'));
Expand Down
22 changes: 12 additions & 10 deletions application/forms/Config/ResourceConfigForm.php
Expand Up @@ -63,12 +63,12 @@ public function add(array $values)
$name = isset($values['name']) ? $values['name'] : '';
if (! $name) {
throw new InvalidArgumentException(t('Resource name missing'));
} elseif ($this->config->{$name} !== null) {
} elseif ($this->config->hasSection($name)) {
throw new InvalidArgumentException(t('Resource already exists'));
}

unset($values['name']);
$this->config->{$name} = $values;
$this->config->setSection($name, $values);
return $this;
}

Expand All @@ -88,14 +88,15 @@ public function edit($name, array $values)
throw new InvalidArgumentException(t('Old resource name missing'));
} elseif (! ($newName = isset($values['name']) ? $values['name'] : '')) {
throw new InvalidArgumentException(t('New resource name missing'));
} elseif (($resourceConfig = $this->config->get($name)) === null) {
} elseif (! $this->config->hasSection($name)) {
throw new InvalidArgumentException(t('Unknown resource provided'));
}

$resourceConfig = $this->config->getSection($name);
$this->config->removeSection($name);
unset($values['name']);
unset($this->config->{$name});
$this->config->{$newName} = array_merge($resourceConfig->toArray(), $values);
return $this->config->{$newName};
$this->config->setSection($newName, $resourceConfig->merge($values));
return $resourceConfig;
}

/**
Expand All @@ -111,11 +112,12 @@ public function remove($name)
{
if (! $name) {
throw new InvalidArgumentException(t('Resource name missing'));
} elseif (($resourceConfig = $this->config->get($name)) === null) {
} elseif (! $this->config->hasSection($name)) {
throw new InvalidArgumentException(t('Unknown resource provided'));
}

unset($this->config->{$name});
$resourceConfig = $this->config->getSection($name);
$this->config->removeSection($name);
return $resourceConfig;
}

Expand Down Expand Up @@ -171,11 +173,11 @@ public function onRequest()
if ($resource !== null) {
if ($resource === '') {
throw new ConfigurationError(t('Resource name missing'));
} elseif (false === isset($this->config->{$resource})) {
} elseif (! $this->config->hasSection($resource)) {
throw new ConfigurationError(t('Unknown resource provided'));
}

$configValues = $this->config->{$resource}->toArray();
$configValues = $this->config->getSection($resource)->toArray();
$configValues['name'] = $resource;
$this->populate($configValues);
}
Expand Down

0 comments on commit ed65052

Please sign in to comment.