From 86205454afb0b851534f7309c668dc092863c8ce Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 19:10:18 +0200 Subject: [ticket/12775] Add customs parameters PHPBB3-12775 --- phpBB/phpbb/di/container_factory.php | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index aeea025b94..a9bc0ea7f7 100644 --- a/phpBB/phpbb/di/container_factory.php +++ b/phpBB/phpbb/di/container_factory.php @@ -93,6 +93,19 @@ class container_factory */ protected $dump_container = true; + /** + * Custom parameters to inject into the container. + * + * Default to true: + * array( + * 'core.root_path', $this->phpbb_root_path, + * 'core.php_ext', $this->php_ext, + * ); + * + * @var array + */ + protected $custom_parameters = null; + /** * Constructor * @@ -146,8 +159,7 @@ class container_factory $this->container->addCompilerPass(new \phpbb\di\pass\kernel_pass()); } - $this->container->setParameter('core.root_path', $this->phpbb_root_path); - $this->container->setParameter('core.php_ext', $this->php_ext); + $this->inject_custom_parameters(); $this->container->compile(); @@ -234,7 +246,7 @@ class container_factory * * @var bool $dump_container */ - public function setDumpContainer($dump_container) + public function set_dump_container($dump_container) { $this->dump_container = $dump_container; } @@ -244,11 +256,21 @@ class container_factory * * @param string $config_path */ - public function setConfigPath($config_path) + public function set_config_path($config_path) { $this->config_path = $config_path; } + /** + * Set custom parameters to inject into the container. + * + * @param array $custom_parameters + */ + public function set_custom_parameters($custom_parameters) + { + $this->custom_parameters = $custom_parameters; + } + /** * Dump the container to the disk. * @@ -348,6 +370,25 @@ class container_factory return $container; } + /** + * Inject the customs parameters into the container + */ + protected function inject_custom_parameters() + { + if ($this->custom_parameters === null) + { + $this->custom_parameters = array( + 'core.root_path', $this->phpbb_root_path, + 'core.php_ext', $this->php_ext, + ); + } + + foreach ($this->custom_parameters as $key => $value) + { + $this->container->setParameter($key, $value); + } + } + /** * Get the filename under which the dumped container will be stored. * -- cgit v1.2.1