diff --git a/core/Application/Environment.php b/core/Application/Environment.php index 967b4d377b0397ff8b11f3675d29aa8a4f7079ac..b70acf461d867e4e65800a7f9964335146c0f21d 100644 --- a/core/Application/Environment.php +++ b/core/Application/Environment.php @@ -41,9 +41,9 @@ class Environment { /** * @internal - * @var EnvironmentManipulator[] + * @var EnvironmentManipulator */ - private static $globalEnvironmentManipulators = array(); + private static $globalEnvironmentManipulator = null; /** * @var string @@ -175,43 +175,40 @@ class Environment * @param EnvironmentManipulator $manipulator * @internal */ - public static function addEnvironmentManipulator(EnvironmentManipulator $manipulator) + public static function setGlobalEnvironmentManipulator(EnvironmentManipulator $manipulator) { - self::$globalEnvironmentManipulators[] = $manipulator; + self::$globalEnvironmentManipulator = $manipulator; } private function getGlobalSettingsProviderOverride() { - foreach (self::$globalEnvironmentManipulators as $manipulator) { - $result = $manipulator->makeGlobalSettingsProvider(); - if (!empty($result)) { - return $result; - } + if (self::$globalEnvironmentManipulator) { + return self::$globalEnvironmentManipulator->makeGlobalSettingsProvider(); + } else { + return null; } - - return null; } private function invokeBeforeContainerCreatedHook() { - foreach (self::$globalEnvironmentManipulators as $manipulator) { - $manipulator->beforeContainerCreated(); + if (self::$globalEnvironmentManipulator) { + return self::$globalEnvironmentManipulator->beforeContainerCreated(); } } private function getExtraDefinitionsFromManipulators() { - $result = array(); - foreach (self::$globalEnvironmentManipulators as $manipulator) { - $result = array_merge($result, $manipulator->getExtraDefinitions()); + if (self::$globalEnvironmentManipulator) { + return self::$globalEnvironmentManipulator->getExtraDefinitions(); + } else { + return array(); } - return $result; } private function invokeEnvironmentBootstrappedHook() { - foreach (self::$globalEnvironmentManipulators as $manipulator) { - $manipulator->onEnvironmentBootstrapped(); + if (self::$globalEnvironmentManipulator) { + self::$globalEnvironmentManipulator->onEnvironmentBootstrapped(); } } } diff --git a/misc/cron/updatetoken.php b/misc/cron/updatetoken.php index 21f28b8cddf850a2d207284debb7b218ecc429f6..c06684e4a32fa81d07fad653fec5cb46ff6962c0 100644 --- a/misc/cron/updatetoken.php +++ b/misc/cron/updatetoken.php @@ -37,7 +37,7 @@ $testmode = in_array('--testmode', $_SERVER['argv']); if ($testmode) { define('PIWIK_TEST_MODE', true); - Environment::addEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables())); + Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables())); } function getPiwikDomain() diff --git a/tests/PHPUnit/proxy/archive.php b/tests/PHPUnit/proxy/archive.php index ba4faeca8486c97ab2c070d99bc3b658c74d0784..a7f4222efe7558a7e9d8d25f272abec613289bd2 100644 --- a/tests/PHPUnit/proxy/archive.php +++ b/tests/PHPUnit/proxy/archive.php @@ -7,7 +7,7 @@ define('PIWIK_ARCHIVE_NO_TRUNCATE', true); require realpath(dirname(__FILE__)) . "/includes.php"; -Environment::addEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables())); +Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables())); // include archive.php, and let 'er rip require_once PIWIK_INCLUDE_PATH . "/misc/cron/archive.php"; diff --git a/tests/PHPUnit/proxy/console b/tests/PHPUnit/proxy/console index f58f09d1fd150b67fbe35c0571d4fc2d34ebf832..31c2b9c2b5fa1c5703fc7ed359543974836d1e4d 100644 --- a/tests/PHPUnit/proxy/console +++ b/tests/PHPUnit/proxy/console @@ -6,6 +6,6 @@ use Piwik\Tests\Framework\TestingEnvironmentVariables; require realpath(dirname(__FILE__)) . "/includes.php"; -Environment::addEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables())); +Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables())); require_once PIWIK_INCLUDE_PATH . "/console"; diff --git a/tests/PHPUnit/proxy/index.php b/tests/PHPUnit/proxy/index.php index 4eb3497882995e1c4834158dbf097f88a44f9c35..fe754756882259dee9e64b1e31e03de2f9988924 100644 --- a/tests/PHPUnit/proxy/index.php +++ b/tests/PHPUnit/proxy/index.php @@ -10,6 +10,6 @@ use Piwik\Tests\Framework\TestingEnvironmentVariables; require realpath(dirname(__FILE__)) . "/includes.php"; -Environment::addEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables())); +Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables())); include PIWIK_INCLUDE_PATH . '/index.php'; \ No newline at end of file diff --git a/tests/PHPUnit/proxy/piwik.php b/tests/PHPUnit/proxy/piwik.php index f1e94930c3a723fedd18e80530c0bf5d3e1b07b8..5e542379f622e3ce5f25e8ce3044336a4e73cf7a 100755 --- a/tests/PHPUnit/proxy/piwik.php +++ b/tests/PHPUnit/proxy/piwik.php @@ -32,7 +32,7 @@ try { }) ); - Environment::addEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables(), $globalObservers)); + Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables(), $globalObservers)); GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';