Skip to content
Extraits de code Groupes Projets
Valider d35273b3 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Remove GlobalSettingsProvider interface and replace w/ GlobalSettingsProvider...

Remove GlobalSettingsProvider interface and replace w/ GlobalSettingsProvider class, the class is the old IniSettingsProvider class.
parent c1e0a666
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 137 ajouts et 166 suppressions
......@@ -13,7 +13,6 @@ use Piwik\Application\Kernel\EnvironmentValidator;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Application\Kernel\PluginList;
use Piwik\Application\Kernel\PluginList\IniPluginList;
use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Container\ContainerFactory;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
......@@ -152,7 +151,7 @@ class Environment
{
// TODO: need to be able to set path global/local/etc. which is in DI... for now works because TestingEnvironment creates
// singleton instance before this method.
return IniSettingsProvider::getSingletonInstance();
return GlobalSettingsProvider::getSingletonInstance();
}
/**
......
......@@ -8,7 +8,7 @@
namespace Piwik\Application\Kernel;
use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Common;
use Piwik\Piwik;
use Piwik\SettingsServer;
......@@ -22,9 +22,9 @@ use Piwik\Translation\Translator;
class EnvironmentValidator
{
/**
* @var IniSettingsProvider
* @var GlobalSettingsProvider
*/
protected $iniSettingsProvider;
protected $settingsProvider;
/**
* @var Translator
......@@ -33,7 +33,7 @@ class EnvironmentValidator
public function __construct(GlobalSettingsProvider $settingsProvider, Translator $translator)
{
$this->iniSettingsProvider = $settingsProvider;
$this->settingsProvider = $settingsProvider;
$this->translator = $translator;
}
......@@ -42,8 +42,8 @@ class EnvironmentValidator
$inTrackerRequest = SettingsServer::isTrackerApiRequest();
$inConsole = Common::isPhpCliMode();
$this->checkConfigFileExists($this->iniSettingsProvider->getPathGlobal());
$this->checkConfigFileExists($this->iniSettingsProvider->getPathLocal(), $startInstaller = !$inTrackerRequest && !$inConsole);
$this->checkConfigFileExists($this->settingsProvider->getPathGlobal());
$this->checkConfigFileExists($this->settingsProvider->getPathLocal(), $startInstaller = !$inTrackerRequest && !$inConsole);
}
/**
......
......@@ -8,24 +8,77 @@
namespace Piwik\Application\Kernel;
use Piwik\Config;
use Piwik\Config\IniFileChain;
/**
* Provides global settings. Global settings are organized in sections where
* each section contains a list of name => value pairs. Setting values can
* be primitive values or arrays of primitive values.
*
* By default, IniSettingsProvider is used which loads all global settings
* from the config.ini.php, global.ini.php files and the optional
* common.ini.php file.
* Uses the config.ini.php, common.ini.php and global.ini.php files to provide global settings.
*
* At the moment a singleton instance of this class is used in order to get tests to pass.
*/
interface GlobalSettingsProvider
class GlobalSettingsProvider
{
private static $instance = null;
/**
* @var IniFileChain
*/
protected $iniFileChain;
/**
* @var string
*/
protected $pathGlobal = null;
/**
* @var string
*/
protected $pathCommon = null;
/**
* @var string
*/
protected $pathLocal = null;
/**
* @param string|null $pathGlobal Path to the global.ini.php file. Or null to use the default.
* @param string|null $pathLocal Path to the config.ini.php file. Or null to use the default.
* @param string|null $pathCommon Path to the common.ini.php file. Or null to use the default.
*/
public function __construct($pathGlobal = null, $pathLocal = null, $pathCommon = null)
{
$this->pathGlobal = $pathGlobal ?: Config::getGlobalConfigPath();
$this->pathCommon = $pathCommon ?: Config::getCommonConfigPath();
$this->pathLocal = $pathLocal ?: Config::getLocalConfigPath();
$this->iniFileChain = new IniFileChain();
$this->reload();
}
public function reload($pathGlobal = null, $pathLocal = null, $pathCommon = null)
{
$this->pathGlobal = $pathGlobal ?: $this->pathGlobal;
$this->pathCommon = $pathCommon ?: $this->pathCommon;
$this->pathLocal = $pathLocal ?: $this->pathLocal;
$this->iniFileChain->reload(array($this->pathGlobal, $this->pathCommon), $this->pathLocal);
}
/**
* Returns a settings section.
*
* @param string $name
* @return array
*/
public function &getSection($name);
public function &getSection($name)
{
$section =& $this->iniFileChain->get($name);
return $section;
}
/**
* Sets a settings section.
......@@ -33,5 +86,54 @@ interface GlobalSettingsProvider
* @param string $name
* @param array $value
*/
public function setSection($name, $value);
public function setSection($name, $value)
{
$this->iniFileChain->set($name, $value);
}
public function getIniFileChain()
{
return $this->iniFileChain;
}
public function getPathGlobal()
{
return $this->pathGlobal;
}
public function getPathLocal()
{
return $this->pathLocal;
}
public function getPathCommon()
{
return $this->pathCommon;
}
public static function getSingletonInstance($pathGlobal = null, $pathLocal = null, $pathCommon = null)
{
if (self::$instance === null) {
self::$instance = new GlobalSettingsProvider($pathGlobal, $pathLocal, $pathCommon);
} else {
// sanity check. the parameters should only be non-null when creating the GlobalSettingsProvider the first time.
// if it's done after, it may point to a problem in the tests. (tests are the only place where these arguments
// should be specified)
if ($pathGlobal !== null
|| $pathLocal !== null
|| $pathCommon !== null
) {
$message = "Unexpected state in GlobalSettingsProvider::getSingletonInstance: singleton already created but paths supplied:\n";
$message .= "global = '$pathGlobal', local = '$pathLocal', common = '$pathCommon'\n";
throw new \Exception($message);
}
}
return self::$instance;
}
public static function unsetSingletonInstance()
{
self::$instance = null;
}
}
\ No newline at end of file
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Config;
use Piwik\Config\IniFileChain;
use Piwik\Application\Kernel\GlobalSettingsProvider;
/**
* Default GlobalSettingsProvider implementation. This provider uses the config.ini.php,
* common.ini.php and global.ini.php files to provide global settings.
*
* At the moment a singleton instance of this class is used in order to get tests to pass.
*/
class IniSettingsProvider implements GlobalSettingsProvider
{
private static $instance = null;
/**
* @var IniFileChain
*/
protected $iniFileChain;
/**
* @var string
*/
protected $pathGlobal = null;
/**
* @var string
*/
protected $pathCommon = null;
/**
* @var string
*/
protected $pathLocal = null;
/**
* @param string|null $pathGlobal Path to the global.ini.php file. Or null to use the default.
* @param string|null $pathLocal Path to the config.ini.php file. Or null to use the default.
* @param string|null $pathCommon Path to the common.ini.php file. Or null to use the default.
*/
public function __construct($pathGlobal = null, $pathLocal = null, $pathCommon = null)
{
$this->pathGlobal = $pathGlobal ?: Config::getGlobalConfigPath();
$this->pathCommon = $pathCommon ?: Config::getCommonConfigPath();
$this->pathLocal = $pathLocal ?: Config::getLocalConfigPath();
$this->iniFileChain = new IniFileChain();
$this->reload();
}
public function reload($pathGlobal = null, $pathLocal = null, $pathCommon = null)
{
$this->pathGlobal = $pathGlobal ?: $this->pathGlobal;
$this->pathCommon = $pathCommon ?: $this->pathCommon;
$this->pathLocal = $pathLocal ?: $this->pathLocal;
$this->iniFileChain->reload(array($this->pathGlobal, $this->pathCommon), $this->pathLocal);
}
public function &getSection($name)
{
$section =& $this->iniFileChain->get($name);
return $section;
}
public function setSection($name, $value)
{
$this->iniFileChain->set($name, $value);
}
public function getIniFileChain()
{
return $this->iniFileChain;
}
public function getPathGlobal()
{
return $this->pathGlobal;
}
public function getPathLocal()
{
return $this->pathLocal;
}
public function getPathCommon()
{
return $this->pathCommon;
}
public static function getSingletonInstance($pathGlobal = null, $pathLocal = null, $pathCommon = null)
{
if (self::$instance === null) {
self::$instance = new IniSettingsProvider($pathGlobal, $pathLocal, $pathCommon);
} else {
// sanity check. the parameters should only be non-null when creating the IniSettingsProvider the first time.
// if it's done after, it may point to a problem in the tests. (tests are the only place where these arguments
// should be specified)
if ($pathGlobal !== null
|| $pathLocal !== null
|| $pathCommon !== null
) {
$message = "Unexpected state in IniSettingsProvider::getSingletonInstance: singleton already created but paths supplied:\n";
$message .= "global = '$pathGlobal', local = '$pathLocal', common = '$pathCommon'\n";
throw new \Exception($message);
}
}
return self::$instance;
}
public static function unsetSingletonInstance()
{
self::$instance = null;
}
}
\ No newline at end of file
......@@ -9,19 +9,18 @@
namespace Piwik\Application\Kernel\PluginList;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Application\Kernel\PluginList;
/**
* Default implementation of the PluginList interface. Uses the [Plugins] section
* in Piwik's INI config to get the activated plugins.
*
* Depends on IniSettingsProvider being used.
* Depends on GlobalSettingsProvider being used.
*/
class IniPluginList implements PluginList
{
/**
* @var IniSettingsProvider
* @var GlobalSettingsProvider
*/
private $settings;
......
......@@ -11,7 +11,6 @@ namespace Piwik;
use Exception;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
/**
* Singleton that provides read & write access to Piwik's INI configuration.
......@@ -52,7 +51,7 @@ class Config extends Singleton
protected $doNotWriteConfigInTests = false;
/**
* @var IniSettingsProvider
* @var GlobalSettingsProvider
*/
protected $settings;
......@@ -60,7 +59,7 @@ class Config extends Singleton
public function __construct($pathGlobal = null, $pathLocal = null, $pathCommon = null)
{
$this->settings = IniSettingsProvider::getSingletonInstance($pathGlobal, $pathLocal, $pathCommon);
$this->settings = GlobalSettingsProvider::getSingletonInstance($pathGlobal, $pathLocal, $pathCommon);
}
/**
......
......@@ -9,7 +9,7 @@ namespace Piwik\Tests\Framework;
use Piwik\Access;
use Piwik\Application\Environment;
use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Archive;
use Piwik\Cache\Backend\File;
use Piwik\Cache as PiwikCache;
......@@ -151,7 +151,7 @@ class Fixture extends \PHPUnit_Framework_Assert
public function performSetUp($setupEnvironmentOnly = false)
{
if ($this->createConfig) {
IniSettingsProvider::unsetSingletonInstance();
GlobalSettingsProvider::unsetSingletonInstance();
}
$this->piwikEnvironment = new Environment('test');
......@@ -329,7 +329,7 @@ class Fixture extends \PHPUnit_Framework_Assert
$_GET = $_REQUEST = array();
Translate::reset();
IniSettingsProvider::unsetSingletonInstance();
GlobalSettingsProvider::unsetSingletonInstance();
Config::setSingletonInstance(new TestConfig());
Config::getInstance()->Plugins; // make sure Plugins exists in a config object for next tests that use Plugin\Manager
......
......@@ -20,7 +20,7 @@ class TestConfig extends Config
public function __construct($pathGlobal = null, $pathLocal = null, $pathCommon = null, $allowSave = false, $doSetTestEnvironment = true)
{
\Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider::unsetSingletonInstance();
\Piwik\Application\Kernel\GlobalSettingsProvider::unsetSingletonInstance();
parent::__construct($pathGlobal, $pathLocal, $pathCommon);
......
......@@ -9,7 +9,7 @@
namespace Piwik\Tests\Framework\TestCase;
use Piwik\Application\Environment;
use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Container\StaticContainer;
use Piwik\EventDispatcher;
use Piwik\Tests\Framework\Mock\File;
......@@ -30,7 +30,7 @@ abstract class UnitTestCase extends \PHPUnit_Framework_TestCase
{
parent::setUp();
IniSettingsProvider::unsetSingletonInstance();
GlobalSettingsProvider::unsetSingletonInstance();
$this->initEnvironment();
......@@ -42,7 +42,7 @@ abstract class UnitTestCase extends \PHPUnit_Framework_TestCase
{
File::reset();
IniSettingsProvider::unsetSingletonInstance();
GlobalSettingsProvider::unsetSingletonInstance();
// make sure the global container exists for the next test case that is executed (since logging can be done
// before a test sets up an environment)
......
......@@ -8,7 +8,7 @@
namespace Piwik\Tests\Integration;
use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Common;
use Piwik\Config;
use Piwik\EventDispatcher;
......@@ -20,7 +20,6 @@ use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Tracker;
use Piwik\Tracker\RequestSet;
use Piwik\Tracker\Request;
use Piwik\Translate;
class TestTracker extends Tracker
{
......@@ -60,7 +59,7 @@ class TrackerTest extends IntegrationTestCase
{
parent::setUp();
IniSettingsProvider::unsetSingletonInstance();
GlobalSettingsProvider::unsetSingletonInstance();
Config::unsetInstance();
Fixture::createWebsite('2014-01-01 00:00:00');
......
......@@ -7,7 +7,7 @@
*/
namespace Piwik\Tests\System;
use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Cache;
use Piwik\Config;
use Piwik\Plugins\Actions\ArchivingHelper;
......@@ -174,7 +174,6 @@ class BlobReportLimitingTest extends SystemTestCase
protected static function setUpConfigOptions()
{
IniSettingsProvider::unsetSingletonInstance();
Config::setSingletonInstance(new TestConfig());
$generalConfig =& Config::getInstance()->General;
......
......@@ -102,7 +102,7 @@ class Piwik_TestingEnvironment
public function getCoreAndSupportedPlugins()
{
$settings = new \Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider();
$settings = new \Piwik\Application\Kernel\GlobalSettingsProvider();
$pluginManager = new PluginManager(new \Piwik\Application\Kernel\PluginList\IniPluginList($settings));
$disabledPlugins = $pluginManager->getCorePluginsDisabledByDefault();
......@@ -151,7 +151,7 @@ class Piwik_TestingEnvironment
\Piwik\Profiler::setupProfilerXHProf($mainRun = false, $setupDuringTracking = true);
}
\Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider::getSingletonInstance(
\Piwik\Application\Kernel\GlobalSettingsProvider::getSingletonInstance(
$testingEnvironment->configFileGlobal,
$testingEnvironment->configFileLocal,
$testingEnvironment->configFileCommon
......
......@@ -9,7 +9,7 @@
namespace Piwik\Tests\Unit;
use PHPUnit_Framework_TestCase;
use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Config;
use Piwik\Tests\Framework\Mock\TestConfig;
......@@ -24,7 +24,7 @@ class DumpConfigTestMockIniFileChain extends Config\IniFileChain
}
}
class MockIniSettingsProvider extends IniSettingsProvider
class MockIniSettingsProvider extends GlobalSettingsProvider
{
public function __construct($configLocal, $configGlobal, $configCommon, $configCache)
{
......@@ -60,7 +60,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
{
parent::setUp();
IniSettingsProvider::unsetSingletonInstance();
GlobalSettingsProvider::unsetSingletonInstance();
}
public function testUserConfigOverwritesSectionGlobalConfigValue()
......
......@@ -10,7 +10,6 @@ namespace Piwik\Tests\Unit\Container;
use DI\Definition\ValueDefinition;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Application\Kernel\GlobalSettingsProvider\IniSettingsProvider;
use Piwik\Container\IniConfigDefinitionSource;
class IniConfigDefinitionSourceTest extends \PHPUnit_Framework_TestCase
......@@ -30,7 +29,7 @@ class IniConfigDefinitionSourceTest extends \PHPUnit_Framework_TestCase
*/
public function getDefinition_withUnknownConfigSection_shouldReturnEmptyArray()
{
$definitionSource = new IniConfigDefinitionSource(new IniSettingsProvider());
$definitionSource = new IniConfigDefinitionSource(new GlobalSettingsProvider());
/** @var ValueDefinition $definition */
$definition = $definitionSource->getDefinition('ini.foo');
......@@ -45,7 +44,7 @@ class IniConfigDefinitionSourceTest extends \PHPUnit_Framework_TestCase
*/
public function getDefinition_withUnknownConfigSectionAndKey_shouldReturnNull()
{
$definitionSource = new IniConfigDefinitionSource(new IniSettingsProvider());
$definitionSource = new IniConfigDefinitionSource(new GlobalSettingsProvider());
$this->assertNull($definitionSource->getDefinition('ini.foo.bar'));
}
......@@ -55,7 +54,7 @@ class IniConfigDefinitionSourceTest extends \PHPUnit_Framework_TestCase
*/
public function getDefinition_withUnknownConfigKey_shouldReturnNull()
{
$definitionSource = new IniConfigDefinitionSource(new IniSettingsProvider());
$definitionSource = new IniConfigDefinitionSource(new GlobalSettingsProvider());
$this->assertNull($definitionSource->getDefinition('ini.General.foo'));
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter