| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Application; |
|
|
| use Piwik\Container\Container; |
| use Piwik\Application\Kernel\EnvironmentValidator; |
| use Piwik\Application\Kernel\GlobalSettingsProvider; |
| use Piwik\Application\Kernel\PluginList; |
| use Piwik\Container\ContainerFactory; |
| use Piwik\Container\StaticContainer; |
| use Piwik\Piwik; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class Environment |
| { |
| |
| |
| |
| |
| private static $globalEnvironmentManipulator = null; |
|
|
| |
| |
| |
| private $environment; |
|
|
| |
| |
| |
| private $definitions; |
|
|
| |
| |
| |
| private $container; |
|
|
| |
| |
| |
| private $globalSettingsProvider; |
|
|
| |
| |
| |
| private $pluginList; |
|
|
| |
| |
| |
| |
| public function __construct($environment, array $definitions = array()) |
| { |
| $this->environment = $environment; |
| $this->definitions = $definitions; |
| } |
|
|
| public function getEnvironmentName() |
| { |
| return $this->environment; |
| } |
|
|
| |
| |
| |
| public function init() |
| { |
| $this->invokeBeforeContainerCreatedHook(); |
|
|
| $this->container = $this->createContainer(); |
| $this->container->set(self::class, $this); |
|
|
| StaticContainer::push($this->container); |
|
|
| $this->validateEnvironment(); |
|
|
| $this->invokeEnvironmentBootstrappedHook(); |
|
|
| Piwik::postEvent('Environment.bootstrapped'); |
| } |
|
|
| |
| |
| |
| public function destroy() |
| { |
| StaticContainer::pop(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getContainer() |
| { |
| return $this->container; |
| } |
|
|
| |
| |
| |
| private function createContainer() |
| { |
| $pluginList = $this->getPluginListCached(); |
| $settings = $this->getGlobalSettingsCached(); |
|
|
| $extraDefinitions = $this->getExtraDefinitionsFromManipulators(); |
| $definitions = array_merge(StaticContainer::getDefinitions(), $extraDefinitions, array($this->definitions)); |
|
|
| $environments = array($this->environment); |
| $environments = array_merge($environments, $this->getExtraEnvironmentsFromManipulators()); |
|
|
| $containerFactory = new ContainerFactory($pluginList, $settings, $environments, $definitions); |
| return $containerFactory->create(); |
| } |
|
|
| protected function getGlobalSettingsCached() |
| { |
| if ($this->globalSettingsProvider === null) { |
| $original = $this->getGlobalSettings(); |
| $globalSettingsProvider = $this->getGlobalSettingsProviderOverride($original); |
|
|
| $this->globalSettingsProvider = $globalSettingsProvider ?: $original; |
| } |
| return $this->globalSettingsProvider; |
| } |
|
|
| protected function getPluginListCached() |
| { |
| if ($this->pluginList === null) { |
| $pluginList = $this->getPluginListOverride(); |
| $this->pluginList = $pluginList ?: $this->getPluginList(); |
| } |
| return $this->pluginList; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| protected function getGlobalSettings() |
| { |
| return new GlobalSettingsProvider(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| protected function getPluginList() |
| { |
| |
| return new PluginList($this->getGlobalSettingsCached()); |
| } |
|
|
| private function validateEnvironment() |
| { |
| |
| $validator = $this->container->get('Piwik\Application\Kernel\EnvironmentValidator'); |
| $validator->validate(); |
| } |
|
|
| |
| |
| |
| public static function setGlobalEnvironmentManipulator(EnvironmentManipulator $manipulator) |
| { |
| self::$globalEnvironmentManipulator = $manipulator; |
| } |
|
|
| private function getGlobalSettingsProviderOverride(GlobalSettingsProvider $original) |
| { |
| if (self::$globalEnvironmentManipulator) { |
| return self::$globalEnvironmentManipulator->makeGlobalSettingsProvider($original); |
| } else { |
| return null; |
| } |
| } |
|
|
| private function invokeBeforeContainerCreatedHook() |
| { |
| if (self::$globalEnvironmentManipulator) { |
| return self::$globalEnvironmentManipulator->beforeContainerCreated(); |
| } |
| } |
|
|
| private function getExtraDefinitionsFromManipulators() |
| { |
| if (self::$globalEnvironmentManipulator) { |
| return self::$globalEnvironmentManipulator->getExtraDefinitions(); |
| } else { |
| return array(); |
| } |
| } |
|
|
| private function invokeEnvironmentBootstrappedHook() |
| { |
| if (self::$globalEnvironmentManipulator) { |
| self::$globalEnvironmentManipulator->onEnvironmentBootstrapped(); |
| } |
| } |
|
|
| private function getExtraEnvironmentsFromManipulators() |
| { |
| if (self::$globalEnvironmentManipulator) { |
| return self::$globalEnvironmentManipulator->getExtraEnvironments(); |
| } else { |
| return array(); |
| } |
| } |
|
|
| private function getPluginListOverride() |
| { |
| if (self::$globalEnvironmentManipulator) { |
| return self::$globalEnvironmentManipulator->makePluginList($this->getGlobalSettingsCached()); |
| } else { |
| return null; |
| } |
| } |
| } |
|
|