From 22e17e9901278893947e89fb5700c438a117759a Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Thu, 28 Aug 2014 11:04:13 +0200 Subject: [PATCH] ResourceFactory: Move available function to platform refs #5514 --- .../Config/Authentication/LdapBackendForm.php | 3 ++- application/forms/Config/ResourceForm.php | 5 +++-- library/Icinga/Application/Platform.php | 15 +++++++++++++++ library/Icinga/Data/ResourceFactory.php | 15 --------------- .../Config/Authentication/LdapBackendFormTest.php | 2 -- .../forms/Config/Resource/ResourceFormTest.php | 2 -- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/application/forms/Config/Authentication/LdapBackendForm.php b/application/forms/Config/Authentication/LdapBackendForm.php index 6dd0d9bd3..cf0afd631 100644 --- a/application/forms/Config/Authentication/LdapBackendForm.php +++ b/application/forms/Config/Authentication/LdapBackendForm.php @@ -5,6 +5,7 @@ namespace Icinga\Form\Config\Authentication; use Exception; +use Icinga\Application\Platform; use Zend_Config; use Icinga\Web\Form; use Icinga\Data\ResourceFactory; @@ -135,7 +136,7 @@ class LdapBackendForm extends BaseBackendForm */ public function isValidAuthenticationBackend() { - if (! ResourceFactory::ldapAvailable()) { + if (! Platform::ldapAvailable()) { /* * It should be possible to run icingaweb without the php ldap extension, when * no ldap backends are needed. When the user tries to create an ldap backend diff --git a/application/forms/Config/ResourceForm.php b/application/forms/Config/ResourceForm.php index 9a48c1f56..9ac85fadc 100644 --- a/application/forms/Config/ResourceForm.php +++ b/application/forms/Config/ResourceForm.php @@ -5,6 +5,7 @@ namespace Icinga\Form\Config; use Exception; +use Icinga\Application\Platform; use Zend_Config; use Zend_Form_Element_Checkbox; use Icinga\Web\Form; @@ -405,14 +406,14 @@ class ResourceForm extends Form * in case they aren't actually used. When the user tries to create a resource that depends on an * uninstalled extension, an error should be displayed. */ - if ($config->db === 'mysql' && !ResourceFactory::mysqlAvailable()) { + if ($config->db === 'mysql' && ! Platform::mysqlAvailable()) { $this->addErrorMessage( t('You need to install the php extension "mysql" and the ' . 'Zend_Pdo_Mysql classes to use MySQL database resources.') ); return false; } - if ($config->db === 'pgsql' && !ResourceFactory::pgsqlAvailable()) { + if ($config->db === 'pgsql' && ! Platform::pgsqlAvailable()) { $this->addErrorMessage( t('You need to install the php extension "pgsql" and the ' . 'Zend_Pdo_Pgsql classes to use PostgreSQL database resources.') diff --git a/library/Icinga/Application/Platform.php b/library/Icinga/Application/Platform.php index 30db869cf..258586da6 100644 --- a/library/Icinga/Application/Platform.php +++ b/library/Icinga/Application/Platform.php @@ -66,4 +66,19 @@ class Platform self::$domain = array_shift(preg_split('~\.~', self::$hostname, 2)); } } + + public static function ldapAvailable() + { + return extension_loaded('ldap'); + } + + public static function pgsqlAvailable() + { + return extension_loaded('pgsql'); + } + + public static function mysqlAvailable() + { + return extension_loaded('mysql'); + } } diff --git a/library/Icinga/Data/ResourceFactory.php b/library/Icinga/Data/ResourceFactory.php index 87f99c0e4..202e1005e 100644 --- a/library/Icinga/Data/ResourceFactory.php +++ b/library/Icinga/Data/ResourceFactory.php @@ -121,19 +121,4 @@ class ResourceFactory implements ConfigAwareFactory } return $resource; } - - public static function ldapAvailable() - { - return extension_loaded('ldap'); - } - - public static function pgsqlAvailable() - { - return extension_loaded('pgsql'); - } - - public static function mysqlAvailable() - { - return extension_loaded('mysql'); - } } diff --git a/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php b/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php index 1255b5957..ebd176099 100644 --- a/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php +++ b/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php @@ -68,8 +68,6 @@ class LdapBackendFormTest extends BaseTestCase protected function setUpResourceFactoryMock() { Mockery::mock('alias:Icinga\Data\ResourceFactory') - ->shouldReceive('ldapAvailable') - ->andReturn(true) ->shouldReceive('getResourceConfig') ->andReturn(new \Zend_Config(array())) ->shouldReceive('createResource') diff --git a/test/php/application/forms/Config/Resource/ResourceFormTest.php b/test/php/application/forms/Config/Resource/ResourceFormTest.php index ccfa9531a..6dba6ce54 100644 --- a/test/php/application/forms/Config/Resource/ResourceFormTest.php +++ b/test/php/application/forms/Config/Resource/ResourceFormTest.php @@ -261,8 +261,6 @@ class ResourceFormTest extends BaseTestCase protected function setUpResourceFactoryMock($resourceMock) { Mockery::mock('alias:Icinga\Data\ResourceFactory') - ->shouldReceive('mysqlAvailable') - ->andReturn(true) ->shouldReceive('createResource') ->with(Mockery::type('\Zend_Config')) ->andReturn($resourceMock);