From c22562f5cdb3db9482a7c6bc2398ebb12cbcfb8b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 30 May 2014 14:57:19 +0200 Subject: [ticket/12620] Allow the user to define multiples environments PHPBB3-12620 --- phpBB/phpbb/di/extension/core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index ca4fa5c082..d203cc7049 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -50,7 +50,7 @@ class core extends Extension public function load(array $config, ContainerBuilder $container) { $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path))); - $loader->load('services.yml'); + $loader->load('config_' . ENVIRONMENT . '.yml'); } /** -- cgit v1.2.1 From 873260589eaa7ac2d7e520ebe321cb8bb2609ce0 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 30 May 2014 15:29:09 +0200 Subject: [ticket/12620] Display error message when the environment isn't available PHPBB3-12620 --- phpBB/phpbb/di/extension/core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index d203cc7049..5fb8d9ad34 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -50,7 +50,7 @@ class core extends Extension public function load(array $config, ContainerBuilder $container) { $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path))); - $loader->load('config_' . ENVIRONMENT . '.yml'); + $loader->load('environment_' . ENVIRONMENT . '.yml'); } /** -- cgit v1.2.1 From 8664d3229a511eb320fef3df6a852d1a20852dae Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 20 Jun 2014 18:49:19 +0200 Subject: [ticket/12620] Split the environments into differents folders PHPBB3-12620 --- phpBB/phpbb/di/extension/core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 5fb8d9ad34..cff0a1e76e 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -50,7 +50,7 @@ class core extends Extension public function load(array $config, ContainerBuilder $container) { $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path))); - $loader->load('environment_' . ENVIRONMENT . '.yml'); + $loader->load(ENVIRONMENT . '/environment.yml'); } /** -- cgit v1.2.1 From b697273aaa53d9f9f4a3d4a53cc6267e906953cd Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 4 Sep 2014 17:06:39 +0200 Subject: [ticket/12620] Use PHPBB_ENVIRONMENT PHPBB3-12620 --- phpBB/phpbb/di/extension/core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index cff0a1e76e..7787602aba 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -50,7 +50,7 @@ class core extends Extension public function load(array $config, ContainerBuilder $container) { $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path))); - $loader->load(ENVIRONMENT . '/environment.yml'); + $loader->load(PHPBB_ENVIRONMENT . '/environment.yml'); } /** -- cgit v1.2.1 From 0bf3d2d962c33ffa606d38e91d04665b78fbd8bc Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 5 Sep 2014 02:29:15 +0200 Subject: [ticket/12620] Add the support of the environments for the ext services We look for an environment.yml file in the config/PHPBB_ENVIRONMENT/ directory of the extensionss. If the directory does not exist we look for the environment.yml file in the 'default' environment and finally for the services.yml file in the config/ directory. PHPBB3-12620 --- phpBB/phpbb/di/extension/ext.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/ext.php b/phpBB/phpbb/di/extension/ext.php index 718c992d2e..330303ca0c 100644 --- a/phpBB/phpbb/di/extension/ext.php +++ b/phpBB/phpbb/di/extension/ext.php @@ -45,10 +45,32 @@ class ext extends Extension { foreach ($this->paths as $path) { - if (file_exists($path . '/config/services.yml')) + $services_directory = false; + $services_file = false; + + if (file_exists($path . 'config/' . PHPBB_ENVIRONMENT . '/environment.yml')) + { + $services_directory = $path . 'config/' . PHPBB_ENVIRONMENT; + $services_file = 'environment.yml'; + } + else if (!is_dir($path . 'config/' . PHPBB_ENVIRONMENT)) + { + if (file_exists($path . 'config/default/environment.yml')) + { + $services_directory = $path . 'config/default'; + $services_file = 'environment.yml'; + } + else if (!is_dir($path . 'config/default') && file_exists($path . '/config/services.yml')) + { + $services_directory = $path . 'config'; + $services_file = 'services.yml'; + } + } + + if ($services_directory && $services_file) { - $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($path . '/config'))); - $loader->load('services.yml'); + $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($services_directory))); + $loader->load($services_file); } } } -- cgit v1.2.1 From aa061aa7c9187009f220e62252a53b49dad7644a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 29 Sep 2014 16:06:56 +0200 Subject: [ticket/12620] Uses a cache directory per environment PHPBB3-12620 --- phpBB/phpbb/di/container_builder.php | 68 ++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 14 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 638c13e86d..b264b0182f 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -13,16 +13,21 @@ namespace phpbb\di; +use Symfony\Component\Config\ConfigCache; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass; class container_builder { - /** @var string phpBB Root Path */ + /** + * @var string phpBB Root Path + */ protected $phpbb_root_path; - /** @var string php file extension */ + /** + * @var string php file extension + */ protected $php_ext; /** @@ -111,6 +116,11 @@ class container_builder */ protected $config_php_file; + /** + * @var string + */ + protected $cache_dir; + /** * Constructor * @@ -133,18 +143,16 @@ class container_builder public function get_container() { $container_filename = $this->get_container_filename(); - if (!defined('DEBUG_CONTAINER') && $this->dump_container && file_exists($container_filename)) + $config_cache = new ConfigCache($container_filename, defined('DEBUG')); + if ($this->dump_container && $config_cache->isFresh()) { require($container_filename); $this->container = new \phpbb_cache_container(); } else { - if ($this->config_path === null) - { - $this->config_path = $this->phpbb_root_path . 'config'; - } - $container_extensions = array(new \phpbb\di\extension\core($this->config_path)); + + $container_extensions = array(new \phpbb\di\extension\core($this->get_config_path())); if ($this->use_extensions) { @@ -178,9 +186,9 @@ class container_builder $this->container->compile(); } - if ($this->dump_container && !defined('DEBUG_CONTAINER')) + if ($this->dump_container) { - $this->dump_container($container_filename); + $this->dump_container($config_cache); } } @@ -266,6 +274,16 @@ class container_builder $this->config_path = $config_path; } + /** + * Returns the path to the container configuration (default: root_path/config) + * + * @return string + */ + protected function get_config_path() + { + return $this->config_path ?: $this->phpbb_root_path . 'config'; + } + /** * Set custom parameters to inject into the container. * @@ -276,12 +294,32 @@ class container_builder $this->custom_parameters = $custom_parameters; } + /** + * Set the path to the cache directory. + * + * @param string $cache_dir Path to the cache directory + */ + public function set_cache_dir($cache_dir) + { + $this->cache_dir = $cache_dir; + } + + /** + * Returns the path to the cache directory (default: root_path/cache/environment). + * + * @return string Path to the cache directory. + */ + protected function get_cache_dir() + { + return $this->cache_dir ?: $this->phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/'; + } + /** * Dump the container to the disk. * - * @param string $container_filename The name of the file. + * @param ConfigCache $cache The config cache */ - protected function dump_container($container_filename) + protected function dump_container($cache) { $dumper = new PhpDumper($this->container); $cached_container_dump = $dumper->dump(array( @@ -289,7 +327,7 @@ class container_builder 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', )); - file_put_contents($container_filename, $cached_container_dump); + $cache->write($cached_container_dump, $this->container->getResources()); } /** @@ -386,6 +424,8 @@ class container_builder ); } + $this->custom_parameters['environment'] = PHPBB_ENVIRONMENT; + foreach ($this->custom_parameters as $key => $value) { $this->container->setParameter($key, $value); @@ -400,6 +440,6 @@ class container_builder protected function get_container_filename() { $filename = str_replace(array('/', '.'), array('slash', 'dot'), $this->phpbb_root_path); - return $this->phpbb_root_path . 'cache/container_' . $filename . '.' . $this->php_ext; + return $this->get_cache_dir() . 'container_' . $filename . '.' . $this->php_ext; } } -- cgit v1.2.1 From 6cbb60d13f75da6d9b6c6d60555ea119df79b5c0 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 4 Oct 2014 16:30:34 +0200 Subject: [ticket/12620] Adds a yaml config file PHPBB3-12620 --- phpBB/phpbb/di/container_builder.php | 63 +++++++++++++++------- .../phpbb/di/extension/container_configuration.php | 38 +++++++++++++ phpBB/phpbb/di/extension/core.php | 37 +++++++++++-- phpBB/phpbb/di/extension/ext.php | 8 +-- 4 files changed, 119 insertions(+), 27 deletions(-) create mode 100644 phpBB/phpbb/di/extension/container_configuration.php (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index b264b0182f..45dbaaf303 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -14,9 +14,13 @@ namespace phpbb\di; use Symfony\Component\Config\ConfigCache; +use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass; +use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; class container_builder { @@ -151,7 +155,6 @@ class container_builder } else { - $container_extensions = array(new \phpbb\di\extension\core($this->get_config_path())); if ($this->use_extensions) @@ -179,7 +182,8 @@ class container_builder } } - $this->inject_custom_parameters(); + $loader = new YamlFileLoader($this->container, new FileLocator(phpbb_realpath($this->get_config_path()))); + $loader->load(PHPBB_ENVIRONMENT . '/config.yml'); if ($this->compile_container) { @@ -400,36 +404,59 @@ class container_builder */ protected function create_container(array $extensions) { - $container = new ContainerBuilder(); + $container = new ContainerBuilder(new ParameterBag($this->get_core_parameters())); + + $extensions_alias = array(); foreach ($extensions as $extension) { $container->registerExtension($extension); - $container->loadFromExtension($extension->getAlias()); + $extensions_alias[] = $extension->getAlias(); + //$container->loadFromExtension($extension->getAlias()); } + $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions_alias)); + return $container; } /** - * Inject the customs parameters into the container - */ - protected function inject_custom_parameters() + * Returns the core parameters. + * + * @return array An array of core parameters + */ + protected function get_core_parameters() { - if ($this->custom_parameters === null) - { - $this->custom_parameters = array( - 'core.root_path' => $this->phpbb_root_path, - 'core.php_ext' => $this->php_ext, - ); - } - - $this->custom_parameters['environment'] = PHPBB_ENVIRONMENT; + return array_merge( + array( + 'core.root_path' => $this->phpbb_root_path, + 'core.php_ext' => $this->php_ext, + 'core.environment' => PHPBB_ENVIRONMENT, + 'core.debug' => DEBUG, + ), + $this->get_env_parameters() + ); + } - foreach ($this->custom_parameters as $key => $value) + /** + * Gets the environment parameters. + * + * Only the parameters starting with "PHPBB__" are considered. + * + * @return array An array of parameters + */ + protected function get_env_parameters() + { + $parameters = array(); + foreach ($_SERVER as $key => $value) { - $this->container->setParameter($key, $value); + if (0 === strpos($key, 'PHPBB__')) + { + $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value; + } } + + return $parameters; } /** diff --git a/phpBB/phpbb/di/extension/container_configuration.php b/phpBB/phpbb/di/extension/container_configuration.php new file mode 100644 index 0000000000..1f1c077472 --- /dev/null +++ b/phpBB/phpbb/di/extension/container_configuration.php @@ -0,0 +1,38 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\di\extension; + +use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; + +class container_configuration implements ConfigurationInterface +{ + + /** + * Generates the configuration tree builder. + * + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder + */ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('core'); + $rootNode + ->children() + ->booleanNode('require_dev_dependencies')->defaultValue(false)->end() + ->end() + ; + return $treeBuilder; + } +} diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 7787602aba..62fcf46ad5 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -13,10 +13,11 @@ namespace phpbb\di\extension; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Config\FileLocator; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** * Container core extension @@ -42,15 +43,41 @@ class core extends Extension /** * Loads a specific configuration. * - * @param array $config An array of configuration values + * @param array $configs An array of configuration values * @param ContainerBuilder $container A ContainerBuilder instance * * @throws \InvalidArgumentException When provided tag is not defined in this extension */ - public function load(array $config, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container) { $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path))); - $loader->load(PHPBB_ENVIRONMENT . '/environment.yml'); + $loader->load(PHPBB_ENVIRONMENT . '/container/environment.yml'); + + $config = $this->getConfiguration($configs, $container); + $config = $this->processConfiguration($config, $configs); + + if ($config['require_dev_dependencies']) + { + if (!class_exists('Goutte\Client', true)) + { + trigger_error( + 'Composer development dependencies have not been set up for the ' . $container->getParameter('core.environment') . ' environment yet, run ' . + "'php ../composer.phar install --dev' from the phpBB directory to do so.", + E_USER_ERROR + ); + } + } + } + + /** + * {@inheritdoc} + */ + public function getConfiguration(array $config, ContainerBuilder $container) + { + $r = new \ReflectionClass('\phpbb\di\extension\container_configuration'); + $container->addResource(new FileResource($r->getFileName())); + + return new container_configuration(); } /** diff --git a/phpBB/phpbb/di/extension/ext.php b/phpBB/phpbb/di/extension/ext.php index 330303ca0c..021e862118 100644 --- a/phpBB/phpbb/di/extension/ext.php +++ b/phpBB/phpbb/di/extension/ext.php @@ -48,16 +48,16 @@ class ext extends Extension $services_directory = false; $services_file = false; - if (file_exists($path . 'config/' . PHPBB_ENVIRONMENT . '/environment.yml')) + if (file_exists($path . 'config/' . PHPBB_ENVIRONMENT . '/container/environment.yml')) { - $services_directory = $path . 'config/' . PHPBB_ENVIRONMENT; + $services_directory = $path . 'config/' . PHPBB_ENVIRONMENT . '/container/'; $services_file = 'environment.yml'; } else if (!is_dir($path . 'config/' . PHPBB_ENVIRONMENT)) { - if (file_exists($path . 'config/default/environment.yml')) + if (file_exists($path . 'config/default/container/environment.yml')) { - $services_directory = $path . 'config/default'; + $services_directory = $path . 'config/default/container/'; $services_file = 'environment.yml'; } else if (!is_dir($path . 'config/default') && file_exists($path . '/config/services.yml')) -- cgit v1.2.1 From 3a167aa0c3eaec6c4b9d322460480786234e0419 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 4 Oct 2014 17:30:10 +0200 Subject: [ticket/12620] Creates one di extension per phpBB extension PHPBB3-12620 --- phpBB/phpbb/di/container_builder.php | 12 ++++- phpBB/phpbb/di/extension/ext.php | 89 ------------------------------------ 2 files changed, 11 insertions(+), 90 deletions(-) delete mode 100644 phpBB/phpbb/di/extension/ext.php (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 45dbaaf303..5ad9336695 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -160,7 +160,17 @@ class container_builder if ($this->use_extensions) { $installed_exts = $this->get_installed_extensions(); - $container_extensions[] = new \phpbb\di\extension\ext($installed_exts); + foreach ($installed_exts as $ext_name => $path) + { + $extension_class = '\\' . str_replace('/', '\\', $ext_name) . '\\di\extension'; + + if (!class_exists($extension_class)) + { + $extension_class = '\phpbb\extension\di\extension_base'; + } + + $container_extensions[] = new $extension_class($ext_name, $path); + } } if ($this->inject_config) diff --git a/phpBB/phpbb/di/extension/ext.php b/phpBB/phpbb/di/extension/ext.php deleted file mode 100644 index 021e862118..0000000000 --- a/phpBB/phpbb/di/extension/ext.php +++ /dev/null @@ -1,89 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\di\extension; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Config\FileLocator; - -/** -* Container ext extension -*/ -class ext extends Extension -{ - protected $paths = array(); - - public function __construct($enabled_extensions) - { - foreach ($enabled_extensions as $ext => $path) - { - $this->paths[] = $path; - } - } - - /** - * Loads a specific configuration. - * - * @param array $config An array of configuration values - * @param ContainerBuilder $container A ContainerBuilder instance - * - * @throws \InvalidArgumentException When provided tag is not defined in this extension - */ - public function load(array $config, ContainerBuilder $container) - { - foreach ($this->paths as $path) - { - $services_directory = false; - $services_file = false; - - if (file_exists($path . 'config/' . PHPBB_ENVIRONMENT . '/container/environment.yml')) - { - $services_directory = $path . 'config/' . PHPBB_ENVIRONMENT . '/container/'; - $services_file = 'environment.yml'; - } - else if (!is_dir($path . 'config/' . PHPBB_ENVIRONMENT)) - { - if (file_exists($path . 'config/default/container/environment.yml')) - { - $services_directory = $path . 'config/default/container/'; - $services_file = 'environment.yml'; - } - else if (!is_dir($path . 'config/default') && file_exists($path . '/config/services.yml')) - { - $services_directory = $path . 'config'; - $services_file = 'services.yml'; - } - } - - if ($services_directory && $services_file) - { - $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($services_directory))); - $loader->load($services_file); - } - } - } - - /** - * Returns the recommended alias to use in XML. - * - * This alias is also the mandatory prefix to use when using YAML. - * - * @return string The alias - */ - public function getAlias() - { - return 'ext'; - } -} -- cgit v1.2.1 From 0b61e3540de353f2bf0a6904a87727e4efe9c5fa Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 4 Oct 2014 17:47:36 +0200 Subject: [ticket/12620] Fix tests PHPBB3-12620 --- phpBB/phpbb/di/container_builder.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 5ad9336695..6216dad978 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -195,6 +195,8 @@ class container_builder $loader = new YamlFileLoader($this->container, new FileLocator(phpbb_realpath($this->get_config_path()))); $loader->load(PHPBB_ENVIRONMENT . '/config.yml'); + $this->inject_custom_parameters(); + if ($this->compile_container) { $this->container->compile(); @@ -430,6 +432,20 @@ class container_builder return $container; } + /** + * Inject the customs parameters into the container + */ + protected function inject_custom_parameters() + { + if ($this->custom_parameters !== null) + { + foreach ($this->custom_parameters as $key => $value) + { + $this->container->setParameter($key, $value); + } + } + } + /** * Returns the core parameters. * -- cgit v1.2.1 From acc91a2bbf28656d4a6917b457ba3dd6b4e02e37 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 11 Nov 2014 17:59:41 +0100 Subject: [ticket/12620] Use the container to get the environment name PHPBB3-12620 --- phpBB/phpbb/di/container_builder.php | 16 +++++++++++++--- phpBB/phpbb/di/extension/core.php | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 6216dad978..c665c8444c 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -193,7 +193,7 @@ class container_builder } $loader = new YamlFileLoader($this->container, new FileLocator(phpbb_realpath($this->get_config_path()))); - $loader->load(PHPBB_ENVIRONMENT . '/config.yml'); + $loader->load($this->container->getParameter('core.environment') . '/config.yml'); $this->inject_custom_parameters(); @@ -327,7 +327,7 @@ class container_builder */ protected function get_cache_dir() { - return $this->cache_dir ?: $this->phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/'; + return $this->cache_dir ?: $this->phpbb_root_path . 'cache/' . $this->get_environment() . '/'; } /** @@ -457,7 +457,7 @@ class container_builder array( 'core.root_path' => $this->phpbb_root_path, 'core.php_ext' => $this->php_ext, - 'core.environment' => PHPBB_ENVIRONMENT, + 'core.environment' => $this->get_environment(), 'core.debug' => DEBUG, ), $this->get_env_parameters() @@ -495,4 +495,14 @@ class container_builder $filename = str_replace(array('/', '.'), array('slash', 'dot'), $this->phpbb_root_path); return $this->get_cache_dir() . 'container_' . $filename . '.' . $this->php_ext; } + + /** + * Return the name of the current environment. + * + * @return string + */ + protected function get_environment() + { + return PHPBB_ENVIRONMENT; + } } diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 62fcf46ad5..ce0d4a869c 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -51,7 +51,7 @@ class core extends Extension public function load(array $configs, ContainerBuilder $container) { $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path))); - $loader->load(PHPBB_ENVIRONMENT . '/container/environment.yml'); + $loader->load($container->getParameter('core.environment') . '/container/environment.yml'); $config = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($config, $configs); -- cgit v1.2.1 From 0a1db77ea85116adf24f9d3f0b92a44f818a107f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 11 Nov 2014 19:10:43 +0100 Subject: [ticket/12620] Add a test using a custom DI extension in an extension PHPBB3-12620 --- phpBB/phpbb/di/container_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index c665c8444c..62bba5baf9 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -162,7 +162,7 @@ class container_builder $installed_exts = $this->get_installed_extensions(); foreach ($installed_exts as $ext_name => $path) { - $extension_class = '\\' . str_replace('/', '\\', $ext_name) . '\\di\extension'; + $extension_class = '\\' . str_replace('/', '\\', $ext_name) . '\\di\\extension'; if (!class_exists($extension_class)) { -- cgit v1.2.1 From 677b5b2cd4937ee6c777728082084c661223dee8 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 20 Nov 2014 22:40:37 +0100 Subject: [ticket/12620] Fix rebase PHPBB3-12620 --- phpBB/phpbb/di/container_builder.php | 2 +- phpBB/phpbb/di/extension/core.php | 40 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 62bba5baf9..125ae28e9b 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -19,7 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass; +use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; class container_builder diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index ce0d4a869c..72d46fb05b 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -25,29 +25,29 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; class core extends Extension { /** - * Config path - * @var string - */ + * Config path + * @var string + */ protected $config_path; /** - * Constructor - * - * @param string $config_path Config path - */ + * Constructor + * + * @param string $config_path Config path + */ public function __construct($config_path) { $this->config_path = $config_path; } /** - * Loads a specific configuration. - * - * @param array $configs An array of configuration values - * @param ContainerBuilder $container A ContainerBuilder instance - * - * @throws \InvalidArgumentException When provided tag is not defined in this extension - */ + * Loads a specific configuration. + * + * @param array $configs An array of configuration values + * @param ContainerBuilder $container A ContainerBuilder instance + * + * @throws \InvalidArgumentException When provided tag is not defined in this extension + */ public function load(array $configs, ContainerBuilder $container) { $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path))); @@ -81,12 +81,12 @@ class core extends Extension } /** - * Returns the recommended alias to use in XML. - * - * This alias is also the mandatory prefix to use when using YAML. - * - * @return string The alias - */ + * Returns the recommended alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * @return string The alias + */ public function getAlias() { return 'core'; -- cgit v1.2.1 From 6850169095f099d8fd9f3886e60237134c77ddb4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 22 Nov 2014 12:33:45 +0100 Subject: [ticket/13266] Enable the debug extension in the development environment PHPBB3-13266 --- phpBB/phpbb/di/extension/container_configuration.php | 8 +++++++- phpBB/phpbb/di/extension/core.php | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/container_configuration.php b/phpBB/phpbb/di/extension/container_configuration.php index 1f1c077472..ee58ec2b74 100644 --- a/phpBB/phpbb/di/extension/container_configuration.php +++ b/phpBB/phpbb/di/extension/container_configuration.php @@ -30,7 +30,13 @@ class container_configuration implements ConfigurationInterface $rootNode = $treeBuilder->root('core'); $rootNode ->children() - ->booleanNode('require_dev_dependencies')->defaultValue(false)->end() + ->booleanNode('require_dev_dependencies')->defaultValue(false)->end() + ->arrayNode('twig') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('enable_debug_extension')->defaultValue(false)->end() + ->end() + ->end() ->end() ; return $treeBuilder; diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 72d46fb05b..451efc8e35 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -67,6 +67,12 @@ class core extends Extension ); } } + + if ($config['twig']['enable_debug_extension']) + { + $definition = $container->getDefinition('template.twig.extensions.debug'); + $definition->addTag('twig.extension'); + } } /** -- cgit v1.2.1 From 4bdef6fd21a5dcab455b0cd1ee2652de606929c3 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Thu, 12 Mar 2015 00:25:00 +0100 Subject: [ticket/13697] Moving filesystem related functions to filesystem service * Moving filesystem service to \phpbb\filesystem namespace * Wraping Symfony's Filesystem component * Moving filesystem related functions from includes/functions.php into \phpbb\filesystem\filesystem Functions moved (and deprecated): - phpbb_chmod - phpbb_is_writable - phpbb_is_absolute - phpbb_own_realpath - phpbb_realpath * Adding interface for filesystem service PHPBB3-13697 --- phpBB/phpbb/di/container_builder.php | 3 ++- phpBB/phpbb/di/extension/core.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 125ae28e9b..2a410db9bd 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -192,7 +192,8 @@ class container_builder } } - $loader = new YamlFileLoader($this->container, new FileLocator(phpbb_realpath($this->get_config_path()))); + $filesystem = new \phpbb\filesystem\filesystem(); + $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); $loader->load($this->container->getParameter('core.environment') . '/config.yml'); $this->inject_custom_parameters(); diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 451efc8e35..c71dc61280 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -50,7 +50,8 @@ class core extends Extension */ public function load(array $configs, ContainerBuilder $container) { - $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path))); + $filesystem = new \phpbb\filesystem\filesystem(); + $loader = new YamlFileLoader($container, new FileLocator($filesystem->realpath($this->config_path))); $loader->load($container->getParameter('core.environment') . '/container/environment.yml'); $config = $this->getConfiguration($configs, $container); -- cgit v1.2.1 From de5a5c41f8e8e47d0740fa97d3d83d57168b18b4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 19 Apr 2015 17:41:29 +0200 Subject: [ticket/13768] Fix deprecations PHPBB3-13768 --- phpBB/phpbb/di/container_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 2a410db9bd..99576f9020 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -150,7 +150,7 @@ class container_builder $config_cache = new ConfigCache($container_filename, defined('DEBUG')); if ($this->dump_container && $config_cache->isFresh()) { - require($container_filename); + require($config_cache->getPath()); $this->container = new \phpbb_cache_container(); } else -- cgit v1.2.1 From f821130c3a4a22efd491aaad962cc84a82dde56a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 25 Nov 2014 17:04:15 +0100 Subject: [ticket/12632] Add twig.debug and twig.auto_reload in config.yml PHPBB3-13206 PHPBB3-12632 --- phpBB/phpbb/di/extension/container_configuration.php | 2 ++ phpBB/phpbb/di/extension/core.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/container_configuration.php b/phpBB/phpbb/di/extension/container_configuration.php index ee58ec2b74..4cc7c7c0d1 100644 --- a/phpBB/phpbb/di/extension/container_configuration.php +++ b/phpBB/phpbb/di/extension/container_configuration.php @@ -34,6 +34,8 @@ class container_configuration implements ConfigurationInterface ->arrayNode('twig') ->addDefaultsIfNotSet() ->children() + ->booleanNode('debug')->defaultValue(null)->end() + ->booleanNode('auto_reload')->defaultValue(null)->end() ->booleanNode('enable_debug_extension')->defaultValue(false)->end() ->end() ->end() diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index c71dc61280..c9e2d4dc5b 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -69,6 +69,20 @@ class core extends Extension } } + // Set the Twig options if defined in the environment + $definition = $container->getDefinition('template.twig.environment'); + $twig_environment_options = $definition->getArgument(6); + if ($config['twig']['debug']) + { + $twig_environment_options['debug'] = true; + } + if ($config['twig']['auto_reload']) + { + $twig_environment_options['auto_reload'] = true; + } + // Replace the 6th argument, the options passed to the environment + $definition->replaceArgument(6, $twig_environment_options); + if ($config['twig']['enable_debug_extension']) { $definition = $container->getDefinition('template.twig.extensions.debug'); -- cgit v1.2.1 From c96e7ef1711932c2236620903bc256b346514dfc Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 26 Apr 2015 19:41:07 +0200 Subject: [ticket/13770] Wither interface for container_builder PHPBB3-13770 --- phpBB/phpbb/di/container_builder.php | 504 +++++++++++++++++------------------ 1 file changed, 247 insertions(+), 257 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 99576f9020..33eb4e59a8 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -13,6 +13,7 @@ namespace phpbb\di; +use phpbb\filesystem\filesystem; use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -24,6 +25,11 @@ use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfiguration class container_builder { + /** + * @var string The environment to use. + */ + protected $environment; + /** * @var string phpBB Root Path */ @@ -35,89 +41,58 @@ class container_builder protected $php_ext; /** - * The container under construction - * - * @var ContainerBuilder - */ + * The container under construction + * + * @var ContainerBuilder + */ protected $container; /** - * @var \phpbb\db\driver\driver_interface - */ - protected $dbal_connection = null; - - /** - * @var array the installed extensions - */ - protected $installed_exts = null; - - /** - * Indicates whether the php config file should be injected into the container (default to true). - * - * @var bool - */ - protected $inject_config = true; - - /** - * Indicates whether extensions should be used (default to true). - * - * @var bool - */ + * Indicates whether extensions should be used (default to true). + * + * @var bool + */ protected $use_extensions = true; /** - * Defines a custom path to find the configuration of the container (default to $this->phpbb_root_path . 'config') - * - * @var string - */ + * Defines a custom path to find the configuration of the container (default to $this->phpbb_root_path . 'config') + * + * @var string + */ protected $config_path = null; /** - * Indicates whether the phpBB compile pass should be used (default to true). - * - * @var bool - */ - protected $use_custom_pass = true; - - /** - * Indicates whether the kernel compile pass should be used (default to true). - * - * @var bool - */ - protected $use_kernel_pass = true; - - /** - * Indicates whether the container should be dumped to the filesystem (default to true). - * - * If DEBUG_CONTAINER is set this option is ignored and a new container is build. - * - * @var bool - */ - protected $dump_container = true; + * Indicates whether the container should be dumped to the filesystem (default to true). + * + * If DEBUG_CONTAINER is set this option is ignored and a new container is build. + * + * @var bool + */ + protected $use_cache = true; /** - * Indicates if the container should be compiled automatically (default to true). - * - * @var bool - */ + * Indicates if the container should be compiled automatically (default to true). + * + * @var bool + */ protected $compile_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 - */ + * Custom parameters to inject into the container. + * + * Default to: + * array( + * 'core.root_path', $this->phpbb_root_path, + * 'core.php_ext', $this->php_ext, + * ); + * + * @var array + */ protected $custom_parameters = null; /** - * @var \phpbb\config_php_file - */ + * @var \phpbb\config_php_file + */ protected $config_php_file; /** @@ -126,295 +101,311 @@ class container_builder protected $cache_dir; /** - * Constructor - * - * @param \phpbb\config_php_file $config_php_file - * @param string $phpbb_root_path Path to the phpbb includes directory. - * @param string $php_ext php file extension - */ - function __construct(\phpbb\config_php_file $config_php_file, $phpbb_root_path, $php_ext) + * @var array + */ + private $container_extensions; + + /** + * Constructor + * + * @param string $phpbb_root_path Path to the phpbb includes directory. + * @param string $php_ext php file extension + */ + function __construct($phpbb_root_path, $php_ext) { - $this->config_php_file = $config_php_file; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; } /** - * Build and return a new Container respecting the current configuration - * - * @return \phpbb_cache_container|ContainerBuilder - */ + * Build and return a new Container respecting the current configuration + * + * @return \phpbb_cache_container|ContainerBuilder + */ public function get_container() { $container_filename = $this->get_container_filename(); $config_cache = new ConfigCache($container_filename, defined('DEBUG')); - if ($this->dump_container && $config_cache->isFresh()) + if ($this->use_cache && $config_cache->isFresh()) { require($config_cache->getPath()); $this->container = new \phpbb_cache_container(); + + return $this->container; } - else - { - $container_extensions = array(new \phpbb\di\extension\core($this->get_config_path())); - if ($this->use_extensions) - { - $installed_exts = $this->get_installed_extensions(); - foreach ($installed_exts as $ext_name => $path) - { - $extension_class = '\\' . str_replace('/', '\\', $ext_name) . '\\di\\extension'; + $this->container_extensions = array(new extension\core($this->get_config_path())); - if (!class_exists($extension_class)) - { - $extension_class = '\phpbb\extension\di\extension_base'; - } + if ($this->use_extensions) + { + $this->load_extensions(); + } - $container_extensions[] = new $extension_class($ext_name, $path); - } - } + // Inject the config + $this->container_extensions[] = new extension\config($this->config_php_file); - if ($this->inject_config) - { - $container_extensions[] = new \phpbb\di\extension\config($this->config_php_file); - } + $this->container = $this->create_container($this->container_extensions); - $this->container = $this->create_container($container_extensions); + // Easy collections through tags + $this->container->addCompilerPass(new pass\collection_pass()); - if ($this->use_custom_pass) - { - // Symfony Kernel Listeners - $this->container->addCompilerPass(new \phpbb\di\pass\collection_pass()); - $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener')); + // Event listeners "phpBB style" + $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener')); - if ($this->use_kernel_pass) - { - $this->container->addCompilerPass(new RegisterListenersPass('dispatcher')); - } - } + // Event listeners "Symfony style" + $this->container->addCompilerPass(new RegisterListenersPass('dispatcher')); - $filesystem = new \phpbb\filesystem\filesystem(); - $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); - $loader->load($this->container->getParameter('core.environment') . '/config.yml'); + $filesystem = new filesystem(); + $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); + $loader->load($this->container->getParameter('core.environment') . '/config.yml'); - $this->inject_custom_parameters(); + $this->inject_custom_parameters(); - if ($this->compile_container) - { - $this->container->compile(); - } + if ($this->compile_container) + { + $this->container->compile(); - if ($this->dump_container) + if ($this->use_cache) { $this->dump_container($config_cache); } } - $this->container->set('config.php', $this->config_php_file); - - if ($this->compile_container) - { - $this->inject_dbal(); - } - return $this->container; } /** - * Set if the extensions should be used. - * - * @param bool $use_extensions - */ - public function set_use_extensions($use_extensions) + * Enable the extensions. + * + * @param string $environment The environment to use + * @return $this + */ + public function with_environment($environment) { - $this->use_extensions = $use_extensions; - } + $this->environment = $environment; - /** - * Set if the phpBB compile pass have to be used. - * - * @param bool $use_custom_pass - */ - public function set_use_custom_pass($use_custom_pass) - { - $this->use_custom_pass = $use_custom_pass; + return $this; } /** - * Set if the kernel compile pass have to be used. - * - * @param bool $use_kernel_pass - */ - public function set_use_kernel_pass($use_kernel_pass) + * Enable the extensions. + * + * @return $this + */ + public function with_extensions() { - $this->use_kernel_pass = $use_kernel_pass; + $this->use_extensions = true; + + return $this; } /** - * Set if the php config file should be injecting into the container. - * - * @param bool $inject_config - */ - public function set_inject_config($inject_config) + * Disable the extensions. + * + * @return $this + */ + public function without_extensions() { - $this->inject_config = $inject_config; + $this->use_extensions = false; + + return $this; } /** - * Set if a dump container should be used. - * - * If DEBUG_CONTAINER is set this option is ignored and a new container is build. - * - * @var bool $dump_container - */ - public function set_dump_container($dump_container) + * Enable the caching of the container. + * + * If DEBUG_CONTAINER is set this option is ignored and a new container is build. + * + * @return $this + */ + public function with_cache() { - $this->dump_container = $dump_container; + $this->use_cache = true; + + return $this; } /** - * Set if the container should be compiled automatically (default to true). - * - * @var bool $dump_container - */ - public function set_compile_container($compile_container) + * Disable the caching of the container. + * + * @return $this + */ + public function without_cache() { - $this->compile_container = $compile_container; + $this->use_cache = false; + + return $this; } /** - * Set a custom path to find the configuration of the container - * - * @param string $config_path - */ - public function set_config_path($config_path) + * Set the cache directory. + * + * @param string $cache_dir The cache directory. + * @return $this + */ + public function with_cache_dir($cache_dir) { - $this->config_path = $config_path; + $this->cache_dir = $cache_dir; + + return $this; } /** - * Returns the path to the container configuration (default: root_path/config) + * Enable the compilation of the container. * - * @return string + * @return $this */ - protected function get_config_path() + public function with_compiled_container() { - return $this->config_path ?: $this->phpbb_root_path . 'config'; + $this->compile_container = true; + + return $this; } /** - * Set custom parameters to inject into the container. - * - * @param array $custom_parameters - */ - public function set_custom_parameters($custom_parameters) + * Disable the compilation of the container. + * + * @return $this + */ + public function without_compiled_container() { - $this->custom_parameters = $custom_parameters; + $this->compile_container = false; + + return $this; } /** - * Set the path to the cache directory. + * Set a custom path to find the configuration of the container. * - * @param string $cache_dir Path to the cache directory + * @param string $config_path + * @return $this */ - public function set_cache_dir($cache_dir) + public function with_config_path($config_path) { - $this->cache_dir = $cache_dir; + $this->config_path = $config_path; + + return $this; } /** - * Returns the path to the cache directory (default: root_path/cache/environment). + * Set custom parameters to inject into the container. * - * @return string Path to the cache directory. + * @param array $custom_parameters + * @return $this */ - protected function get_cache_dir() + public function with_custom_parameters($custom_parameters) { - return $this->cache_dir ?: $this->phpbb_root_path . 'cache/' . $this->get_environment() . '/'; + $this->custom_parameters = $custom_parameters; + + return $this; } /** - * Dump the container to the disk. - * - * @param ConfigCache $cache The config cache - */ - protected function dump_container($cache) + * Set custom parameters to inject into the container. + * + * @param \phpbb\config_php_file $config_php_file + * @return $this + */ + public function with_config(\phpbb\config_php_file $config_php_file) { - $dumper = new PhpDumper($this->container); - $cached_container_dump = $dumper->dump(array( - 'class' => 'phpbb_cache_container', - 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', - )); + $this->config_php_file = $config_php_file; - $cache->write($cached_container_dump, $this->container->getResources()); + return $this; } /** - * Inject the connection into the container if one was opened. - */ - protected function inject_dbal() + * Returns the path to the container configuration (default: root_path/config) + * + * @return string + */ + protected function get_config_path() { - if ($this->dbal_connection !== null) - { - $this->container->get('dbal.conn')->set_driver($this->dbal_connection); - } + return $this->config_path ?: $this->phpbb_root_path . 'config'; } /** - * Get DB connection. - * - * @return \phpbb\db\driver\driver_interface - */ - protected function get_dbal_connection() + * Returns the path to the cache directory (default: root_path/cache/environment). + * + * @return string Path to the cache directory. + */ + protected function get_cache_dir() { - if ($this->dbal_connection === null) - { - $dbal_driver_class = $this->config_php_file->convert_30_dbms_to_31($this->config_php_file->get('dbms')); - $this->dbal_connection = new $dbal_driver_class(); - $this->dbal_connection->sql_connect( - $this->config_php_file->get('dbhost'), - $this->config_php_file->get('dbuser'), - $this->config_php_file->get('dbpasswd'), - $this->config_php_file->get('dbname'), - $this->config_php_file->get('dbport'), - defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK - ); - } - - return $this->dbal_connection; + return $this->cache_dir ?: $this->phpbb_root_path . 'cache/' . $this->get_environment() . '/'; } /** - * Get enabled extensions. - * - * @return array enabled extensions - */ - protected function get_installed_extensions() + * Load the enabled extensions. + */ + protected function load_extensions() { - $db = $this->get_dbal_connection(); - $extension_table = $this->config_php_file->get('table_prefix') . 'ext'; + if ($this->config_php_file !== null) + { + // Build an intermediate container to load the ext list from the database + $container_builder = new container_builder($this->phpbb_root_path, $this->php_ext); + $ext_container = $container_builder + ->without_cache() + ->without_extensions() + ->with_config($this->config_php_file) + ->with_environment('production') + ->without_compiled_container() + ->get_container() + ; + + $ext_container->register('cache.driver', '\\phpbb\\cache\\driver\\null'); + $ext_container->compile(); + + $extensions = $ext_container->get('ext.manager')->all_enabled(); + + // Load each extension found + foreach ($extensions as $ext_name => $path) + { + $extension_class = '\\' . str_replace('/', '\\', $ext_name) . '\\di\\extension'; - $sql = 'SELECT * - FROM ' . $extension_table . ' - WHERE ext_active = 1'; + if (!class_exists($extension_class)) + { + $extension_class = '\\phpbb\\extension\\di\\extension_base'; + } - $result = $db->sql_query($sql); - $rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); + $this->container_extensions[] = new $extension_class($ext_name, $path); - $exts = array(); - foreach ($rows as $row) + // Load extension autoloader + $filename = $path . 'vendor/autoload.php'; + if (file_exists($filename)) + { + require $filename; + } + } + } + else { - $exts[$row['ext_name']] = $this->phpbb_root_path . 'ext/' . $row['ext_name'] . '/'; + // To load the extensions we need the database credentials. + // Automatically disable the extensions if we don't have them. + $this->use_extensions = false; } + } - return $exts; + /** + * Dump the container to the disk. + * + * @param ConfigCache $cache The config cache + */ + protected function dump_container($cache) + { + $dumper = new PhpDumper($this->container); + $cached_container_dump = $dumper->dump(array( + 'class' => 'phpbb_cache_container', + 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', + )); + + $cache->write($cached_container_dump, $this->container->getResources()); } /** - * Create the ContainerBuilder object - * - * @param array $extensions Array of Container extension objects - * @return ContainerBuilder object - */ + * Create the ContainerBuilder object + * + * @param array $extensions Array of Container extension objects + * @return ContainerBuilder object + */ protected function create_container(array $extensions) { $container = new ContainerBuilder(new ParameterBag($this->get_core_parameters())); @@ -425,7 +416,6 @@ class container_builder { $container->registerExtension($extension); $extensions_alias[] = $extension->getAlias(); - //$container->loadFromExtension($extension->getAlias()); } $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions_alias)); @@ -487,10 +477,10 @@ class container_builder } /** - * Get the filename under which the dumped container will be stored. - * - * @return string Path for dumped container - */ + * Get the filename under which the dumped container will be stored. + * + * @return string Path for dumped container + */ protected function get_container_filename() { $filename = str_replace(array('/', '.'), array('slash', 'dot'), $this->phpbb_root_path); @@ -504,6 +494,6 @@ class container_builder */ protected function get_environment() { - return PHPBB_ENVIRONMENT; + return $this->environment ?: PHPBB_ENVIRONMENT; } } -- cgit v1.2.1 From 549fe66d90eed1d6a4fee6f5f706c73455d73596 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 26 Apr 2015 21:30:50 +0200 Subject: [ticket/13770] Update tests PHPBB3-13770 --- phpBB/phpbb/di/container_builder.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 33eb4e59a8..3886bfdd5d 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -142,7 +142,10 @@ class container_builder } // Inject the config - $this->container_extensions[] = new extension\config($this->config_php_file); + if ($this->config_php_file) + { + $this->container_extensions[] = new extension\config($this->config_php_file); + } $this->container = $this->create_container($this->container_extensions); -- cgit v1.2.1 From 02af9385a13543f3f6bd9cb1500fd8508bcd35ac Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sun, 10 May 2015 23:54:49 +0200 Subject: [ticket/13770] Fix tests PHPBB3-13770 --- phpBB/phpbb/di/container_builder.php | 83 +++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 35 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 3886bfdd5d..9f2e860932 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -21,6 +21,7 @@ use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; +use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; class container_builder @@ -130,50 +131,55 @@ class container_builder { require($config_cache->getPath()); $this->container = new \phpbb_cache_container(); - - return $this->container; } - - $this->container_extensions = array(new extension\core($this->get_config_path())); - - if ($this->use_extensions) + else { - $this->load_extensions(); - } + $this->container_extensions = array(new extension\core($this->get_config_path())); - // Inject the config - if ($this->config_php_file) - { - $this->container_extensions[] = new extension\config($this->config_php_file); - } + if ($this->use_extensions) + { + $this->load_extensions(); + } - $this->container = $this->create_container($this->container_extensions); + // Inject the config + if ($this->config_php_file) + { + $this->container_extensions[] = new extension\config($this->config_php_file); + } - // Easy collections through tags - $this->container->addCompilerPass(new pass\collection_pass()); + $this->container = $this->create_container($this->container_extensions); - // Event listeners "phpBB style" - $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener')); + // Easy collections through tags + $this->container->addCompilerPass(new pass\collection_pass()); - // Event listeners "Symfony style" - $this->container->addCompilerPass(new RegisterListenersPass('dispatcher')); + // Event listeners "phpBB style" + $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener')); - $filesystem = new filesystem(); - $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); - $loader->load($this->container->getParameter('core.environment') . '/config.yml'); + // Event listeners "Symfony style" + $this->container->addCompilerPass(new RegisterListenersPass('dispatcher')); - $this->inject_custom_parameters(); + $filesystem = new filesystem(); + $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); + $loader->load($this->container->getParameter('core.environment') . '/config.yml'); - if ($this->compile_container) - { - $this->container->compile(); + $this->inject_custom_parameters(); - if ($this->use_cache) + if ($this->compile_container) { - $this->dump_container($config_cache); + $this->container->compile(); + + if ($this->use_cache) + { + $this->dump_container($config_cache); + } } } + if ($this->compile_container && $this->config_php_file) + { + $this->container->set('config.php', $this->config_php_file); + } + return $this->container; } @@ -394,13 +400,20 @@ class container_builder */ protected function dump_container($cache) { - $dumper = new PhpDumper($this->container); - $cached_container_dump = $dumper->dump(array( - 'class' => 'phpbb_cache_container', - 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', - )); + try + { + $dumper = new PhpDumper($this->container); + $cached_container_dump = $dumper->dump(array( + 'class' => 'phpbb_cache_container', + 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', + )); - $cache->write($cached_container_dump, $this->container->getResources()); + $cache->write($cached_container_dump, $this->container->getResources()); + } + catch (IOException $e) + { + // Don't fail if the cache isn't writeable + } } /** -- cgit v1.2.1 From 2b25c5bd35a1a5e668d0f4e644cfabf995e1a537 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Mon, 11 May 2015 00:19:50 +0200 Subject: [ticket/13770] Use dummy cache driver PHPBB3-13770 --- phpBB/phpbb/di/container_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 9f2e860932..4a31339b9a 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -360,7 +360,7 @@ class container_builder ->get_container() ; - $ext_container->register('cache.driver', '\\phpbb\\cache\\driver\\null'); + $ext_container->register('cache.driver', '\\phpbb\\cache\\driver\\dummy'); $ext_container->compile(); $extensions = $ext_container->get('ext.manager')->all_enabled(); -- cgit v1.2.1 From 7a65b0cc4ea172446064d4f83b74438a9dacef09 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Tue, 19 May 2015 21:59:41 +0200 Subject: [ticket/13849] Fix development environment PHPBB3-13849 --- phpBB/phpbb/di/extension/core.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index c9e2d4dc5b..91b321a684 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -71,7 +71,7 @@ class core extends Extension // Set the Twig options if defined in the environment $definition = $container->getDefinition('template.twig.environment'); - $twig_environment_options = $definition->getArgument(6); + $twig_environment_options = $definition->getArgument(7); if ($config['twig']['debug']) { $twig_environment_options['debug'] = true; @@ -80,8 +80,8 @@ class core extends Extension { $twig_environment_options['auto_reload'] = true; } - // Replace the 6th argument, the options passed to the environment - $definition->replaceArgument(6, $twig_environment_options); + // Replace the 8th argument, the options passed to the environment + $definition->replaceArgument(7, $twig_environment_options); if ($config['twig']['enable_debug_extension']) { -- cgit v1.2.1 From 98cb70f5d2e42dafa48413713cc60ddd881c54c6 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Tue, 23 Jun 2015 14:31:18 +0200 Subject: [ticket/13961] Move service_collection to di/service_collection namespace PHPBB3-13961 --- phpBB/phpbb/di/service_collection.php | 79 ---------------------- .../di/service_collection/service_collection.php | 79 ++++++++++++++++++++++ .../service_collection_iterator.php | 46 +++++++++++++ phpBB/phpbb/di/service_collection_iterator.php | 46 ------------- 4 files changed, 125 insertions(+), 125 deletions(-) delete mode 100644 phpBB/phpbb/di/service_collection.php create mode 100644 phpBB/phpbb/di/service_collection/service_collection.php create mode 100644 phpBB/phpbb/di/service_collection/service_collection_iterator.php delete mode 100644 phpBB/phpbb/di/service_collection_iterator.php (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php deleted file mode 100644 index 82ca9bf679..0000000000 --- a/phpBB/phpbb/di/service_collection.php +++ /dev/null @@ -1,79 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\di; - -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** -* Collection of services to be configured at container compile time. -*/ -class service_collection extends \ArrayObject -{ - /** - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected $container; - - /** - * Constructor - * - * @param ContainerInterface $container Container object - */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - /** - * {@inheritdoc} - */ - public function getIterator() - { - return new service_collection_iterator($this); - } - - // Because of a PHP issue we have to redefine offsetExists - // (even with a call to the parent): - // https://bugs.php.net/bug.php?id=66834 - // https://bugs.php.net/bug.php?id=67067 - // But it triggers a sniffer issue that we have to skip - // @codingStandardsIgnoreStart - /** - * {@inheritdoc} - */ - public function offsetExists($index) - { - return parent::offsetExists($index); - } - // @codingStandardsIgnoreEnd - - /** - * {@inheritdoc} - */ - public function offsetGet($index) - { - return $this->container->get($index); - } - - /** - * Add a service to the collection - * - * @param string $name The service name - * @return null - */ - public function add($name) - { - $this->offsetSet($name, null); - } -} diff --git a/phpBB/phpbb/di/service_collection/service_collection.php b/phpBB/phpbb/di/service_collection/service_collection.php new file mode 100644 index 0000000000..8085128fed --- /dev/null +++ b/phpBB/phpbb/di/service_collection/service_collection.php @@ -0,0 +1,79 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\di\service_collection; + +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** +* Collection of services to be configured at container compile time. +*/ +class service_collection extends \ArrayObject +{ + /** + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** + * Constructor + * + * @param ContainerInterface $container Container object + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + /** + * {@inheritdoc} + */ + public function getIterator() + { + return new service_collection_iterator($this); + } + + // Because of a PHP issue we have to redefine offsetExists + // (even with a call to the parent): + // https://bugs.php.net/bug.php?id=66834 + // https://bugs.php.net/bug.php?id=67067 + // But it triggers a sniffer issue that we have to skip + // @codingStandardsIgnoreStart + /** + * {@inheritdoc} + */ + public function offsetExists($index) + { + return parent::offsetExists($index); + } + // @codingStandardsIgnoreEnd + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + return $this->container->get($index); + } + + /** + * Add a service to the collection + * + * @param string $name The service name + * @return null + */ + public function add($name) + { + $this->offsetSet($name, null); + } +} diff --git a/phpBB/phpbb/di/service_collection/service_collection_iterator.php b/phpBB/phpbb/di/service_collection/service_collection_iterator.php new file mode 100644 index 0000000000..76e22b048e --- /dev/null +++ b/phpBB/phpbb/di/service_collection/service_collection_iterator.php @@ -0,0 +1,46 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\di\service_collection; + +/** +* Iterator which loads the services when they are requested +*/ +class service_collection_iterator extends \ArrayIterator +{ + /** + * @var \phpbb\di\service_collection\service_collection + */ + protected $collection; + + /** + * Construct an ArrayIterator for service_collection + * + * @param \phpbb\di\service_collection\service_collection $collection The collection to iterate over + * @param int $flags Flags to control the behaviour of the ArrayObject object. + * @see ArrayObject::setFlags() + */ + public function __construct(service_collection $collection, $flags = 0) + { + parent::__construct($collection, $flags); + $this->collection = $collection; + } + + /** + * {@inheritdoc} + */ + public function current() + { + return $this->collection->offsetGet($this->key()); + } +} diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php deleted file mode 100644 index 0d031ab52d..0000000000 --- a/phpBB/phpbb/di/service_collection_iterator.php +++ /dev/null @@ -1,46 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\di; - -/** -* Iterator which loads the services when they are requested -*/ -class service_collection_iterator extends \ArrayIterator -{ - /** - * @var \phpbb\di\service_collection - */ - protected $collection; - - /** - * Construct an ArrayIterator for service_collection - * - * @param \phpbb\di\service_collection $collection The collection to iterate over - * @param int $flags Flags to control the behaviour of the ArrayObject object. - * @see ArrayObject::setFlags() - */ - public function __construct(service_collection $collection, $flags = 0) - { - parent::__construct($collection, $flags); - $this->collection = $collection; - } - - /** - * {@inheritdoc} - */ - public function current() - { - return $this->collection->offsetGet($this->key()); - } -} -- cgit v1.2.1 From a91c4e4f96309401f2e1a7a05ccadc876781298e Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Wed, 24 Jun 2015 13:08:19 +0200 Subject: [ticket/13961] Add ordered service collection PHPBB3-13961 --- phpBB/phpbb/di/pass/collection_pass.php | 11 ++- .../ordered_service_collection.php | 108 +++++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 phpBB/phpbb/di/service_collection/ordered_service_collection.php (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/pass/collection_pass.php b/phpBB/phpbb/di/pass/collection_pass.php index a5c054674e..ccc1250c20 100644 --- a/phpBB/phpbb/di/pass/collection_pass.php +++ b/phpBB/phpbb/di/pass/collection_pass.php @@ -37,7 +37,16 @@ class collection_pass implements CompilerPassInterface foreach ($container->findTaggedServiceIds($data[0]['tag']) as $service_id => $service_data) { - $definition->addMethodCall('add', array($service_id)); + if (substr($definition->getClass(), -strlen('ordered_service_collection')) === 'ordered_service_collection') + { + $arguments = array($service_id, $service_data[0]['order']); + } + else + { + $arguments = array($service_id); + } + + $definition->addMethodCall('add', $arguments); } } } diff --git a/phpBB/phpbb/di/service_collection/ordered_service_collection.php b/phpBB/phpbb/di/service_collection/ordered_service_collection.php new file mode 100644 index 0000000000..01d0914ad4 --- /dev/null +++ b/phpBB/phpbb/di/service_collection/ordered_service_collection.php @@ -0,0 +1,108 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\di\service_collection; + +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Collection of services in a specified order + */ +class ordered_service_collection extends service_collection +{ + /** + * @var bool + */ + protected $is_ordered; + + /** + * @var array + */ + protected $service_ids; + + /** + * Constructor + * + * @param ContainerInterface $container Container object + */ + public function __construct(ContainerInterface $container) + { + $this->is_ordered = false; + $this->service_ids = array(); + + parent::__construct($container); + } + + /** + * {@inheritdoc} + */ + public function offsetExists($index) + { + if (!$this->is_ordered) + { + $this->sort_services(); + } + + return parent::offsetExists($index); + } + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + if (!$this->is_ordered) + { + $this->sort_services(); + } + + return parent::offsetGet($index); + } + + /** + * Adds a service ID to the collection + * + * @param string $service_id + * @param int $order + */ + public function add($service_id, $order) + { + if ($this->is_ordered) + { + return; + } + + $order = (int) $order; + + $this->service_ids[$order][] = $service_id; + } + + protected function sort_services() + { + if ($this->is_ordered) + { + return; + } + + ksort($this->service_ids); + foreach ($this->service_ids as $service_order_group) + { + foreach ($service_order_group as $service_id) + { + $this->offsetSet($service_id, null); + } + } + + $this->is_ordered = true; + } +} -- cgit v1.2.1 From a34a65afdce363aed65d037576278aef4484b753 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Wed, 24 Jun 2015 15:15:38 +0200 Subject: [ticket/13691] Add services when the iterator requested PHPBB3-13691 --- .../di/service_collection/ordered_service_collection.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/service_collection/ordered_service_collection.php b/phpBB/phpbb/di/service_collection/ordered_service_collection.php index 01d0914ad4..f012abcd09 100644 --- a/phpBB/phpbb/di/service_collection/ordered_service_collection.php +++ b/phpBB/phpbb/di/service_collection/ordered_service_collection.php @@ -43,6 +43,19 @@ class ordered_service_collection extends service_collection parent::__construct($container); } + /** + * {@inheritdoc} + */ + public function getIterator() + { + if (!$this->is_ordered) + { + $this->sort_services(); + } + + return new service_collection_iterator($this); + } + /** * {@inheritdoc} */ -- cgit v1.2.1 From 050de400d741d48403fb32485933d1fe161e89b0 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Wed, 24 Jun 2015 15:35:47 +0200 Subject: [ticket/13961] Fix compatibility issue with parent class PHPBB3-13961 --- phpBB/phpbb/di/service_collection/ordered_service_collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/service_collection/ordered_service_collection.php b/phpBB/phpbb/di/service_collection/ordered_service_collection.php index f012abcd09..8d56434504 100644 --- a/phpBB/phpbb/di/service_collection/ordered_service_collection.php +++ b/phpBB/phpbb/di/service_collection/ordered_service_collection.php @@ -88,7 +88,7 @@ class ordered_service_collection extends service_collection * @param string $service_id * @param int $order */ - public function add($service_id, $order) + public function add($service_id, $order = 0) { if ($this->is_ordered) { -- cgit v1.2.1 From b09293d5ff38633d506083cffc0a9dd2c98c15c4 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Fri, 26 Jun 2015 01:02:04 +0200 Subject: [ticket/13961] Move back service_collections under original namespace PHPBB3-13961 --- phpBB/phpbb/di/ordered_service_collection.php | 121 +++++++++++++++++++++ phpBB/phpbb/di/service_collection.php | 79 ++++++++++++++ .../ordered_service_collection.php | 121 --------------------- .../di/service_collection/service_collection.php | 79 -------------- .../service_collection_iterator.php | 46 -------- phpBB/phpbb/di/service_collection_iterator.php | 46 ++++++++ 6 files changed, 246 insertions(+), 246 deletions(-) create mode 100644 phpBB/phpbb/di/ordered_service_collection.php create mode 100644 phpBB/phpbb/di/service_collection.php delete mode 100644 phpBB/phpbb/di/service_collection/ordered_service_collection.php delete mode 100644 phpBB/phpbb/di/service_collection/service_collection.php delete mode 100644 phpBB/phpbb/di/service_collection/service_collection_iterator.php create mode 100644 phpBB/phpbb/di/service_collection_iterator.php (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/ordered_service_collection.php b/phpBB/phpbb/di/ordered_service_collection.php new file mode 100644 index 0000000000..46f397a004 --- /dev/null +++ b/phpBB/phpbb/di/ordered_service_collection.php @@ -0,0 +1,121 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\di; + +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Collection of services in a specified order + */ +class ordered_service_collection extends service_collection +{ + /** + * @var bool + */ + protected $is_ordered; + + /** + * @var array + */ + protected $service_ids; + + /** + * Constructor + * + * @param ContainerInterface $container Container object + */ + public function __construct(ContainerInterface $container) + { + $this->is_ordered = false; + $this->service_ids = array(); + + parent::__construct($container); + } + + /** + * {@inheritdoc} + */ + public function getIterator() + { + if (!$this->is_ordered) + { + $this->sort_services(); + } + + return new service_collection_iterator($this); + } + + /** + * {@inheritdoc} + */ + public function offsetExists($index) + { + if (!$this->is_ordered) + { + $this->sort_services(); + } + + return parent::offsetExists($index); + } + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + if (!$this->is_ordered) + { + $this->sort_services(); + } + + return parent::offsetGet($index); + } + + /** + * Adds a service ID to the collection + * + * @param string $service_id + * @param int $order + */ + public function add($service_id, $order = 0) + { + if ($this->is_ordered) + { + return; + } + + $order = (int) $order; + + $this->service_ids[$order][] = $service_id; + } + + protected function sort_services() + { + if ($this->is_ordered) + { + return; + } + + ksort($this->service_ids); + foreach ($this->service_ids as $service_order_group) + { + foreach ($service_order_group as $service_id) + { + $this->offsetSet($service_id, null); + } + } + + $this->is_ordered = true; + } +} diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php new file mode 100644 index 0000000000..82ca9bf679 --- /dev/null +++ b/phpBB/phpbb/di/service_collection.php @@ -0,0 +1,79 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\di; + +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** +* Collection of services to be configured at container compile time. +*/ +class service_collection extends \ArrayObject +{ + /** + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** + * Constructor + * + * @param ContainerInterface $container Container object + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + /** + * {@inheritdoc} + */ + public function getIterator() + { + return new service_collection_iterator($this); + } + + // Because of a PHP issue we have to redefine offsetExists + // (even with a call to the parent): + // https://bugs.php.net/bug.php?id=66834 + // https://bugs.php.net/bug.php?id=67067 + // But it triggers a sniffer issue that we have to skip + // @codingStandardsIgnoreStart + /** + * {@inheritdoc} + */ + public function offsetExists($index) + { + return parent::offsetExists($index); + } + // @codingStandardsIgnoreEnd + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + return $this->container->get($index); + } + + /** + * Add a service to the collection + * + * @param string $name The service name + * @return null + */ + public function add($name) + { + $this->offsetSet($name, null); + } +} diff --git a/phpBB/phpbb/di/service_collection/ordered_service_collection.php b/phpBB/phpbb/di/service_collection/ordered_service_collection.php deleted file mode 100644 index 8d56434504..0000000000 --- a/phpBB/phpbb/di/service_collection/ordered_service_collection.php +++ /dev/null @@ -1,121 +0,0 @@ - - * @license GNU General Public License, version 2 (GPL-2.0) - * - * For full copyright and license information, please see - * the docs/CREDITS.txt file. - * - */ - -namespace phpbb\di\service_collection; - -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Collection of services in a specified order - */ -class ordered_service_collection extends service_collection -{ - /** - * @var bool - */ - protected $is_ordered; - - /** - * @var array - */ - protected $service_ids; - - /** - * Constructor - * - * @param ContainerInterface $container Container object - */ - public function __construct(ContainerInterface $container) - { - $this->is_ordered = false; - $this->service_ids = array(); - - parent::__construct($container); - } - - /** - * {@inheritdoc} - */ - public function getIterator() - { - if (!$this->is_ordered) - { - $this->sort_services(); - } - - return new service_collection_iterator($this); - } - - /** - * {@inheritdoc} - */ - public function offsetExists($index) - { - if (!$this->is_ordered) - { - $this->sort_services(); - } - - return parent::offsetExists($index); - } - - /** - * {@inheritdoc} - */ - public function offsetGet($index) - { - if (!$this->is_ordered) - { - $this->sort_services(); - } - - return parent::offsetGet($index); - } - - /** - * Adds a service ID to the collection - * - * @param string $service_id - * @param int $order - */ - public function add($service_id, $order = 0) - { - if ($this->is_ordered) - { - return; - } - - $order = (int) $order; - - $this->service_ids[$order][] = $service_id; - } - - protected function sort_services() - { - if ($this->is_ordered) - { - return; - } - - ksort($this->service_ids); - foreach ($this->service_ids as $service_order_group) - { - foreach ($service_order_group as $service_id) - { - $this->offsetSet($service_id, null); - } - } - - $this->is_ordered = true; - } -} diff --git a/phpBB/phpbb/di/service_collection/service_collection.php b/phpBB/phpbb/di/service_collection/service_collection.php deleted file mode 100644 index 8085128fed..0000000000 --- a/phpBB/phpbb/di/service_collection/service_collection.php +++ /dev/null @@ -1,79 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\di\service_collection; - -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** -* Collection of services to be configured at container compile time. -*/ -class service_collection extends \ArrayObject -{ - /** - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected $container; - - /** - * Constructor - * - * @param ContainerInterface $container Container object - */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - /** - * {@inheritdoc} - */ - public function getIterator() - { - return new service_collection_iterator($this); - } - - // Because of a PHP issue we have to redefine offsetExists - // (even with a call to the parent): - // https://bugs.php.net/bug.php?id=66834 - // https://bugs.php.net/bug.php?id=67067 - // But it triggers a sniffer issue that we have to skip - // @codingStandardsIgnoreStart - /** - * {@inheritdoc} - */ - public function offsetExists($index) - { - return parent::offsetExists($index); - } - // @codingStandardsIgnoreEnd - - /** - * {@inheritdoc} - */ - public function offsetGet($index) - { - return $this->container->get($index); - } - - /** - * Add a service to the collection - * - * @param string $name The service name - * @return null - */ - public function add($name) - { - $this->offsetSet($name, null); - } -} diff --git a/phpBB/phpbb/di/service_collection/service_collection_iterator.php b/phpBB/phpbb/di/service_collection/service_collection_iterator.php deleted file mode 100644 index 76e22b048e..0000000000 --- a/phpBB/phpbb/di/service_collection/service_collection_iterator.php +++ /dev/null @@ -1,46 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\di\service_collection; - -/** -* Iterator which loads the services when they are requested -*/ -class service_collection_iterator extends \ArrayIterator -{ - /** - * @var \phpbb\di\service_collection\service_collection - */ - protected $collection; - - /** - * Construct an ArrayIterator for service_collection - * - * @param \phpbb\di\service_collection\service_collection $collection The collection to iterate over - * @param int $flags Flags to control the behaviour of the ArrayObject object. - * @see ArrayObject::setFlags() - */ - public function __construct(service_collection $collection, $flags = 0) - { - parent::__construct($collection, $flags); - $this->collection = $collection; - } - - /** - * {@inheritdoc} - */ - public function current() - { - return $this->collection->offsetGet($this->key()); - } -} diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php new file mode 100644 index 0000000000..0d031ab52d --- /dev/null +++ b/phpBB/phpbb/di/service_collection_iterator.php @@ -0,0 +1,46 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\di; + +/** +* Iterator which loads the services when they are requested +*/ +class service_collection_iterator extends \ArrayIterator +{ + /** + * @var \phpbb\di\service_collection + */ + protected $collection; + + /** + * Construct an ArrayIterator for service_collection + * + * @param \phpbb\di\service_collection $collection The collection to iterate over + * @param int $flags Flags to control the behaviour of the ArrayObject object. + * @see ArrayObject::setFlags() + */ + public function __construct(service_collection $collection, $flags = 0) + { + parent::__construct($collection, $flags); + $this->collection = $collection; + } + + /** + * {@inheritdoc} + */ + public function current() + { + return $this->collection->offsetGet($this->key()); + } +} -- cgit v1.2.1 From c80cf87b90eefab664ecf69f29796f9390a3ff17 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Sat, 27 Jun 2015 12:49:10 +0200 Subject: [ticket/13961] Allow the collection to be modified runtime PHPBB3-13961 --- phpBB/phpbb/di/ordered_service_collection.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/ordered_service_collection.php b/phpBB/phpbb/di/ordered_service_collection.php index 46f397a004..046012ae5b 100644 --- a/phpBB/phpbb/di/ordered_service_collection.php +++ b/phpBB/phpbb/di/ordered_service_collection.php @@ -90,14 +90,9 @@ class ordered_service_collection extends service_collection */ public function add($service_id, $order = 0) { - if ($this->is_ordered) - { - return; - } - $order = (int) $order; - $this->service_ids[$order][] = $service_id; + $this->is_ordered = false; } protected function sort_services() @@ -107,6 +102,7 @@ class ordered_service_collection extends service_collection return; } + $this->exchangeArray(array()); ksort($this->service_ids); foreach ($this->service_ids as $service_order_group) { -- cgit v1.2.1 From 108b9833a10ff657d5d55ba1f976ad7314ecbfa3 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Thu, 2 Jul 2015 16:10:55 +0200 Subject: [ticket/13961] Define behaviour when the array is modified in a loop PHPBB3-13961 --- phpBB/phpbb/di/service_collection_iterator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php index 0d031ab52d..31bc156e99 100644 --- a/phpBB/phpbb/di/service_collection_iterator.php +++ b/phpBB/phpbb/di/service_collection_iterator.php @@ -32,7 +32,7 @@ class service_collection_iterator extends \ArrayIterator */ public function __construct(service_collection $collection, $flags = 0) { - parent::__construct($collection, $flags); + parent::__construct($collection->getArrayCopy(), $flags); $this->collection = $collection; } -- cgit v1.2.1 From b284e31a9e55e5fc617a229439282cc6d746432a Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Thu, 9 Jul 2015 15:29:49 +0200 Subject: [ticket/13740] Add option to have class names in service collections PHPBB3-13740 --- phpBB/phpbb/di/service_collection.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index 82ca9bf679..24f358ca84 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -25,6 +25,11 @@ class service_collection extends \ArrayObject */ protected $container; + /** + * @var array + */ + protected $service_classes; + /** * Constructor * @@ -33,6 +38,7 @@ class service_collection extends \ArrayObject public function __construct(ContainerInterface $container) { $this->container = $container; + $this->service_classes = array(); } /** @@ -76,4 +82,25 @@ class service_collection extends \ArrayObject { $this->offsetSet($name, null); } + + /** + * Add a service's class to the collection + * + * @param string $service_id + * @param string $class + */ + public function add_service_classes($service_id, $class) + { + $this->service_classes[$service_id] = $class; + } + + /** + * Get services' classes + * + * @return array + */ + public function get_service_classes() + { + return $this->service_classes; + } } -- cgit v1.2.1 From e967f3c1a81eab0f14daf314b7fb1b2001e4d220 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Thu, 9 Jul 2015 19:08:28 +0200 Subject: [ticket/13740] Fix itteration problems, implement class name aware collections PHPBB3-13740 --- phpBB/phpbb/di/pass/collection_pass.php | 13 ++++++++++++- phpBB/phpbb/di/service_collection.php | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/pass/collection_pass.php b/phpBB/phpbb/di/pass/collection_pass.php index ccc1250c20..341f88518d 100644 --- a/phpBB/phpbb/di/pass/collection_pass.php +++ b/phpBB/phpbb/di/pass/collection_pass.php @@ -34,10 +34,12 @@ class collection_pass implements CompilerPassInterface foreach ($container->findTaggedServiceIds('service_collection') as $id => $data) { $definition = $container->getDefinition($id); + $is_ordered_collection = (substr($definition->getClass(), -strlen('ordered_service_collection')) === 'ordered_service_collection'); + $is_class_name_aware = (isset($data[0]['class_name_aware']) && $data[0]['class_name_aware']); foreach ($container->findTaggedServiceIds($data[0]['tag']) as $service_id => $service_data) { - if (substr($definition->getClass(), -strlen('ordered_service_collection')) === 'ordered_service_collection') + if ($is_ordered_collection) { $arguments = array($service_id, $service_data[0]['order']); } @@ -46,6 +48,15 @@ class collection_pass implements CompilerPassInterface $arguments = array($service_id); } + if ($is_class_name_aware) + { + $service_definition = $container->getDefinition($service_id); + $definition->addMethodCall('add_service_class', array( + $service_id, + $service_definition->getClass() + )); + } + $definition->addMethodCall('add', $arguments); } } diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index 24f358ca84..8e9175e204 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -89,7 +89,7 @@ class service_collection extends \ArrayObject * @param string $service_id * @param string $class */ - public function add_service_classes($service_id, $class) + public function add_service_class($service_id, $class) { $this->service_classes[$service_id] = $class; } -- cgit v1.2.1 From 8e5e954438b232f4ce7aec6a5db3d52b974c07a8 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sun, 22 Feb 2015 23:36:27 +0100 Subject: [ticket/13645] Move the feeds to controllers PHPBB3-13645 --- phpBB/phpbb/di/container_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index c9adbe7d63..fb391760ce 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -465,7 +465,7 @@ class container_builder 'core.root_path' => $this->phpbb_root_path, 'core.php_ext' => $this->php_ext, 'core.environment' => $this->get_environment(), - 'core.debug' => DEBUG, + 'core.debug' => defined('DEBUG') ? DEBUG : false, ), $this->get_env_parameters() ); -- cgit v1.2.1 From 17e7a89a60f700efc8a0b082b7a82005e6288e80 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 24 Aug 2015 12:04:22 +0200 Subject: [ticket/14124] Automatically translate exceptions in CLI PHPBB3-14124 --- phpBB/phpbb/di/extension/container_configuration.php | 6 ++++++ phpBB/phpbb/di/extension/core.php | 7 +++++++ 2 files changed, 13 insertions(+) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/container_configuration.php b/phpBB/phpbb/di/extension/container_configuration.php index 4cc7c7c0d1..4585d6509e 100644 --- a/phpBB/phpbb/di/extension/container_configuration.php +++ b/phpBB/phpbb/di/extension/container_configuration.php @@ -31,6 +31,12 @@ class container_configuration implements ConfigurationInterface $rootNode ->children() ->booleanNode('require_dev_dependencies')->defaultValue(false)->end() + ->arrayNode('debug') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('exceptions')->defaultValue(false)->end() + ->end() + ->end() ->arrayNode('twig') ->addDefaultsIfNotSet() ->children() diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 91b321a684..c48a80a558 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -80,6 +80,7 @@ class core extends Extension { $twig_environment_options['auto_reload'] = true; } + // Replace the 8th argument, the options passed to the environment $definition->replaceArgument(7, $twig_environment_options); @@ -88,6 +89,12 @@ class core extends Extension $definition = $container->getDefinition('template.twig.extensions.debug'); $definition->addTag('twig.extension'); } + + // Set the debug options + foreach ($config['debug'] as $name => $value) + { + $container->setParameter('debug.' . $name, $value); + } } /** -- cgit v1.2.1 From 8f5a0ad6f73e7b7757b02c827436384c96069b5a Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Fri, 24 Jul 2015 09:20:50 +0200 Subject: [ticket/14039] Revamp updater PHPBB3-14039 --- phpBB/phpbb/di/container_builder.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index fb391760ce..0a94aac98d 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -355,6 +355,7 @@ class container_builder ->without_cache() ->without_extensions() ->with_config($this->config_php_file) + ->with_config_path($this->get_config_path()) ->with_environment('production') ->without_compiled_container() ->get_container() -- cgit v1.2.1 From d44e34aa141361781eae67814278b390cebaf4e5 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 22 Dec 2015 18:48:12 +0100 Subject: [ticket/14377] Allow extensions to register compiler pass PHPBB3-14377 --- phpBB/phpbb/di/container_builder.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 0a94aac98d..8f175c966c 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -22,6 +22,7 @@ use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\Filesystem\Exception\IOException; +use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; class container_builder @@ -158,6 +159,11 @@ class container_builder // Event listeners "Symfony style" $this->container->addCompilerPass(new RegisterListenersPass('dispatcher')); + if ($this->use_extensions) + { + $this->register_ext_compiler_pass(); + } + $filesystem = new filesystem(); $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); $loader->load($this->container->getParameter('core.environment') . '/config.yml'); @@ -512,4 +518,34 @@ class container_builder { return $this->environment ?: PHPBB_ENVIRONMENT; } + + private function register_ext_compiler_pass() + { + $finder = new Finder(); + $finder + ->name('*_pass.php') + ->path('di/pass') + ->files() + ->ignoreDotFiles(true) + ->ignoreUnreadableDirs(true) + ->ignoreVCS(true) + ->followLinks() + ->in($this->phpbb_root_path . 'ext/') + ; + + /** @var \SplFileInfo $pass */ + foreach ($finder as $pass) + { + $filename = $pass->getPathname(); + $filename = substr($filename, 0, -strlen('.' . $pass->getExtension())); + $filename = str_replace(DIRECTORY_SEPARATOR, '/', $filename); + $className = preg_replace('#^.*ext/#', '', $filename); + $className = '\\' . str_replace('/', '\\', $className); + + if (class_exists($className) && in_array('Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface', class_implements($className), true)) + { + $this->container->addCompilerPass(new $className()); + } + } + } } -- cgit v1.2.1 From 78349ed80f24cb61ad05f997e97d805cc5b0409f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 11 Dec 2015 21:31:27 +0100 Subject: [ticket/14306] Automatically enable a safe mode when container building fails PHPBB3-14306 --- phpBB/phpbb/di/container_builder.php | 109 +++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 49 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 8f175c966c..95d6483e34 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -90,7 +90,7 @@ class container_builder * * @var array */ - protected $custom_parameters = null; + protected $custom_parameters = []; /** * @var \phpbb\config_php_file @@ -126,67 +126,80 @@ class container_builder */ public function get_container() { - $container_filename = $this->get_container_filename(); - $config_cache = new ConfigCache($container_filename, defined('DEBUG')); - if ($this->use_cache && $config_cache->isFresh()) - { - require($config_cache->getPath()); - $this->container = new \phpbb_cache_container(); - } - else - { - $this->container_extensions = array(new extension\core($this->get_config_path())); - - if ($this->use_extensions) + try { + $container_filename = $this->get_container_filename(); + $config_cache = new ConfigCache($container_filename, defined('DEBUG')); + if ($this->use_cache && $config_cache->isFresh()) { - $this->load_extensions(); + require($config_cache->getPath()); + $this->container = new \phpbb_cache_container(); } - - // Inject the config - if ($this->config_php_file) + else { - $this->container_extensions[] = new extension\config($this->config_php_file); - } + $this->container_extensions = array(new extension\core($this->get_config_path())); - $this->container = $this->create_container($this->container_extensions); + if ($this->use_extensions) + { + $this->load_extensions(); + } - // Easy collections through tags - $this->container->addCompilerPass(new pass\collection_pass()); + // Inject the config + if ($this->config_php_file) + { + $this->container_extensions[] = new extension\config($this->config_php_file); + } - // Event listeners "phpBB style" - $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener')); + $this->container = $this->create_container($this->container_extensions); - // Event listeners "Symfony style" - $this->container->addCompilerPass(new RegisterListenersPass('dispatcher')); + // Easy collections through tags + $this->container->addCompilerPass(new pass\collection_pass()); - if ($this->use_extensions) - { - $this->register_ext_compiler_pass(); - } + // Event listeners "phpBB style" + $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener')); - $filesystem = new filesystem(); - $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); - $loader->load($this->container->getParameter('core.environment') . '/config.yml'); + // Event listeners "Symfony style" + $this->container->addCompilerPass(new RegisterListenersPass('dispatcher')); - $this->inject_custom_parameters(); + if ($this->use_extensions) + { + $this->register_ext_compiler_pass(); + } - if ($this->compile_container) - { - $this->container->compile(); + $filesystem = new filesystem(); + $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); + $loader->load($this->container->getParameter('core.environment') . '/config.yml'); - if ($this->use_cache) + $this->inject_custom_parameters(); + + if ($this->compile_container) { - $this->dump_container($config_cache); + $this->container->compile(); + + if ($this->use_cache) + { + $this->dump_container($config_cache); + } } } - } - if ($this->compile_container && $this->config_php_file) + if ($this->compile_container && $this->config_php_file) + { + $this->container->set('config.php', $this->config_php_file); + } + + return $this->container; + } + catch (\Exception $e) { - $this->container->set('config.php', $this->config_php_file); + return $this + ->without_extensions() + ->without_cache() + ->with_custom_parameters(array_merge($this->custom_parameters, [ + 'container_exception' => $e, + ])) + ->get_container() + ; } - - return $this->container; } /** @@ -451,13 +464,11 @@ class container_builder */ protected function inject_custom_parameters() { - if ($this->custom_parameters !== null) + foreach ($this->custom_parameters as $key => $value) { - foreach ($this->custom_parameters as $key => $value) - { - $this->container->setParameter($key, $value); - } + $this->container->setParameter($key, $value); } + } /** -- cgit v1.2.1 From 761fa9da52e92efafa6839938113ddb55cd85f17 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 15 Dec 2015 20:13:59 +0100 Subject: [ticket/14306] Doesn't try to build a "safe" container in the dev env PHPBB3-14306 --- phpBB/phpbb/di/container_builder.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 95d6483e34..6e6fb5c7fb 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -113,7 +113,7 @@ class container_builder * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension */ - function __construct($phpbb_root_path, $php_ext) + public function __construct($phpbb_root_path, $php_ext) { $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; @@ -191,14 +191,26 @@ class container_builder } catch (\Exception $e) { - return $this - ->without_extensions() - ->without_cache() - ->with_custom_parameters(array_merge($this->custom_parameters, [ - 'container_exception' => $e, - ])) - ->get_container() - ; + // Don't try to recover if we are in the development environment + if ($this->get_environment() === 'development') { + throw $e; + } + + try + { + return $this + ->without_extensions() + ->without_cache() + ->with_custom_parameters(array_merge($this->custom_parameters, [ + 'container_exception' => $e, + ])) + ->get_container(); + } + catch (\Exception $_) + { + // Rethrow the original exception if it's still failing + throw $e; + } } } -- cgit v1.2.1 From 7f8b6c02c6380d44d2bc3c402cfa5e9953d4819b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 15 Dec 2015 20:18:55 +0100 Subject: [ticket/14306] Update the error message PHPBB3-14306 --- phpBB/phpbb/di/container_builder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 6e6fb5c7fb..d90f78c0d9 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -192,7 +192,8 @@ class container_builder catch (\Exception $e) { // Don't try to recover if we are in the development environment - if ($this->get_environment() === 'development') { + if ($this->get_environment() === 'development') + { throw $e; } -- cgit v1.2.1 From 6594ef8b1e0b63f911fbcc2b8859fcfb09977e2f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 9 Jan 2016 15:32:11 +0100 Subject: [ticket/14306] CS and correctly handle exception loop PHPBB3-14306 --- phpBB/phpbb/di/container_builder.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index d90f78c0d9..433847b285 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -107,6 +107,9 @@ class container_builder */ private $container_extensions; + /** @var \Exception */ + private $build_exception; + /** * Constructor * @@ -126,7 +129,8 @@ class container_builder */ public function get_container() { - try { + try + { $container_filename = $this->get_container_filename(); $config_cache = new ConfigCache($container_filename, defined('DEBUG')); if ($this->use_cache && $config_cache->isFresh()) @@ -197,8 +201,10 @@ class container_builder throw $e; } - try + if ($this->build_exception === null) { + $this->build_exception = $e; + return $this ->without_extensions() ->without_cache() @@ -207,10 +213,10 @@ class container_builder ])) ->get_container(); } - catch (\Exception $_) + else { // Rethrow the original exception if it's still failing - throw $e; + throw $this->build_exception; } } } -- cgit v1.2.1 From cc38bf550b6d044938532d96a98dd92767e69b61 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 25 Jan 2016 13:50:23 +0100 Subject: [ticket/14129] Caches extensions autoloaders PHPBB3-14129 --- phpBB/phpbb/di/container_builder.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 433847b285..9583da14f5 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -135,6 +135,11 @@ class container_builder $config_cache = new ConfigCache($container_filename, defined('DEBUG')); if ($this->use_cache && $config_cache->isFresh()) { + if ($this->use_extensions) + { + require($this->get_autoload_filename()); + } + require($config_cache->getPath()); $this->container = new \phpbb_cache_container(); } @@ -405,6 +410,15 @@ class container_builder $extensions = $ext_container->get('ext.manager')->all_enabled(); // Load each extension found + $autoloaders = ' $path) { $extension_class = '\\' . str_replace('/', '\\', $ext_name) . '\\di\\extension'; @@ -420,9 +434,14 @@ class container_builder $filename = $path . 'vendor/autoload.php'; if (file_exists($filename)) { - require $filename; + $autoloaders .= "require('{$filename}');\n"; } } + + $configCache = new ConfigCache($this->get_autoload_filename(), false); + $configCache->write($autoloaders); + + require($this->get_autoload_filename()); } else { @@ -539,6 +558,16 @@ class container_builder return $this->get_cache_dir() . 'container_' . md5($this->phpbb_root_path) . '.' . $this->php_ext; } + /** + * Get the filename under which the dumped extensions autoloader will be stored. + * + * @return string Path for dumped extensions autoloader + */ + protected function get_autoload_filename() + { + return $this->get_cache_dir() . 'autoload_' . md5($this->phpbb_root_path) . '.' . $this->php_ext; + } + /** * Return the name of the current environment. * -- cgit v1.2.1 From 632418ad6e844c3d71a16a47cac8ae3a22a02f1e Mon Sep 17 00:00:00 2001 From: Mark Shaw Date: Thu, 18 Feb 2016 23:56:53 -0500 Subject: [ticket/14489] Fix bug where extension custom compiler pass cannot be found. This is returning an extra / on my machine which throws off the next code block, and then the class can't be found. PHPBB3-14489 --- phpBB/phpbb/di/container_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 9583da14f5..2fb248082f 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -589,7 +589,7 @@ class container_builder ->ignoreUnreadableDirs(true) ->ignoreVCS(true) ->followLinks() - ->in($this->phpbb_root_path . 'ext/') + ->in($this->phpbb_root_path . 'ext') ; /** @var \SplFileInfo $pass */ -- cgit v1.2.1 From 56c2caf6c0778c0da48fe0ac688c893777b89ee4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 23 Mar 2016 22:48:58 +0100 Subject: [ticket/14555] Uniformize cache directory usages PHPBB3-14555 --- phpBB/phpbb/di/container_builder.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 2fb248082f..7bfe1bbb87 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -522,6 +522,7 @@ class container_builder 'core.php_ext' => $this->php_ext, 'core.environment' => $this->get_environment(), 'core.debug' => defined('DEBUG') ? DEBUG : false, + 'core.cache_dir' => $this->get_cache_dir(), ), $this->get_env_parameters() ); -- cgit v1.2.1 From 5cdbef860de6eccbf1ad62390668acc7fbccb46a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 23 Mar 2016 11:26:30 +0100 Subject: [ticket/13616] Uses symfony/proxy-manager-bridge to lazy load twig lexer PHPBB3-13616 --- phpBB/phpbb/di/container_builder.php | 8 +++++++- phpBB/phpbb/di/extension/core.php | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 7bfe1bbb87..0462fb60c2 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -14,6 +14,8 @@ namespace phpbb\di; use phpbb\filesystem\filesystem; +use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; +use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -460,7 +462,10 @@ class container_builder { try { - $dumper = new PhpDumper($this->container); + $dumper = new PhpDumper($this->container); + $proxy_dumper = new ProxyDumper(); + $dumper->setProxyDumper($proxy_dumper); + $cached_container_dump = $dumper->dump(array( 'class' => 'phpbb_cache_container', 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', @@ -483,6 +488,7 @@ class container_builder protected function create_container(array $extensions) { $container = new ContainerBuilder(new ParameterBag($this->get_core_parameters())); + $container->setProxyInstantiator(new RuntimeInstantiator()); $extensions_alias = array(); diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index c48a80a558..2faeff3636 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -71,7 +71,7 @@ class core extends Extension // Set the Twig options if defined in the environment $definition = $container->getDefinition('template.twig.environment'); - $twig_environment_options = $definition->getArgument(7); + $twig_environment_options = $definition->getArgument(6); if ($config['twig']['debug']) { $twig_environment_options['debug'] = true; @@ -81,8 +81,8 @@ class core extends Extension $twig_environment_options['auto_reload'] = true; } - // Replace the 8th argument, the options passed to the environment - $definition->replaceArgument(7, $twig_environment_options); + // Replace the 7th argument, the options passed to the environment + $definition->replaceArgument(6, $twig_environment_options); if ($config['twig']['enable_debug_extension']) { -- cgit v1.2.1 From 5754cbfec445919dd8b7f261de33d75cbdc78fdd Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 3 Apr 2016 16:14:50 +0200 Subject: [ticket/13616] Fix CS + constant in the core extension PHPBB3-13616 --- phpBB/phpbb/di/extension/core.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 2faeff3636..29c0b0e44e 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -24,6 +24,8 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; */ class core extends Extension { + const TWIG_OPTIONS_POSITION = 6; + /** * Config path * @var string @@ -71,7 +73,7 @@ class core extends Extension // Set the Twig options if defined in the environment $definition = $container->getDefinition('template.twig.environment'); - $twig_environment_options = $definition->getArgument(6); + $twig_environment_options = $definition->getArgument(static::TWIG_OPTIONS_POSITION); if ($config['twig']['debug']) { $twig_environment_options['debug'] = true; @@ -82,7 +84,7 @@ class core extends Extension } // Replace the 7th argument, the options passed to the environment - $definition->replaceArgument(6, $twig_environment_options); + $definition->replaceArgument(static::TWIG_OPTIONS_POSITION, $twig_environment_options); if ($config['twig']['enable_debug_extension']) { -- cgit v1.2.1 From 7bf8006b67f6a2f56317fb6c4ab25ca623757ba5 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 4 Apr 2016 21:32:46 +0200 Subject: [ticket/14198] Use the build option to calculate the container cache filename PHPBB3-14198 --- phpBB/phpbb/di/container_builder.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 7bfe1bbb87..b9284d04be 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -556,7 +556,13 @@ class container_builder */ protected function get_container_filename() { - return $this->get_cache_dir() . 'container_' . md5($this->phpbb_root_path) . '.' . $this->php_ext; + $container_params = [ + 'phpbb_root_path' => $this->phpbb_root_path, + 'use_extensions' => $this->use_extensions, + 'config_path' => $this->config_path, + ]; + + return $this->get_cache_dir() . 'container_' . md5(implode(',', $container_params)) . '.' . $this->php_ext; } /** @@ -566,7 +572,13 @@ class container_builder */ protected function get_autoload_filename() { - return $this->get_cache_dir() . 'autoload_' . md5($this->phpbb_root_path) . '.' . $this->php_ext; + $container_params = [ + 'phpbb_root_path' => $this->phpbb_root_path, + 'use_extensions' => $this->use_extensions, + 'config_path' => $this->config_path, + ]; + + return $this->get_cache_dir() . 'autoload_' . md5(implode(',', $container_params)) . '.' . $this->php_ext; } /** -- cgit v1.2.1 From 7fedc19cc422a00ad460f7f9dc41e916c67073ef Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 9 Dec 2016 08:17:51 +0100 Subject: [ticket/14891] Use own proxy instantiator for open_basedir compatibility Also reverted random_compat lib to 1.4.x. PHPBB3-14891 --- phpBB/phpbb/di/container_builder.php | 2 +- phpBB/phpbb/di/proxy_instantiator.php | 74 +++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 phpBB/phpbb/di/proxy_instantiator.php (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index b6854673c2..6412ccea46 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -488,7 +488,7 @@ class container_builder protected function create_container(array $extensions) { $container = new ContainerBuilder(new ParameterBag($this->get_core_parameters())); - $container->setProxyInstantiator(new RuntimeInstantiator()); + $container->setProxyInstantiator(new proxy_instantiator($this->get_cache_dir())); $extensions_alias = array(); diff --git a/phpBB/phpbb/di/proxy_instantiator.php b/phpBB/phpbb/di/proxy_instantiator.php new file mode 100644 index 0000000000..28d9972cd7 --- /dev/null +++ b/phpBB/phpbb/di/proxy_instantiator.php @@ -0,0 +1,74 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\di; + +use \bantu\IniGetWrapper\IniGetWrapper; +use ProxyManager\Configuration; +use ProxyManager\Factory\LazyLoadingValueHolderFactory; +use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; +use ProxyManager\Proxy\LazyLoadingInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface; + +/** + * Runtime lazy loading proxy generator extended for allowing use while using + * open_basedir restrictions + * + * Original author: Marco Pivetta + */ +class proxy_instantiator implements InstantiatorInterface +{ + /** + * @var LazyLoadingValueHolderFactory + */ + private $factory; + + /** + * proxy_instantiator constructor + * @param string $cache_dir Cache dir for fall back when using open_basedir + */ + public function __construct($cache_dir) + { + $config = new Configuration(); + + // Prevent trying to write to system temp dir in case of open_basedir + // restrictions being in effect + $ini_wrapper = new IniGetWrapper(); + if ($ini_wrapper->getString('open_basedir') || !file_exists(sys_get_temp_dir())) + { + $config->setProxiesTargetDir($cache_dir); + } + $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy()); + + $this->factory = new LazyLoadingValueHolderFactory($config); + } + + /** + * {@inheritdoc} + */ + public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator) + { + return $this->factory->createProxy( + $definition->getClass(), + function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) { + $wrappedInstance = call_user_func($realInstantiator); + + $proxy->setProxyInitializer(null); + + return true; + } + ); + } +} -- cgit v1.2.1 From 5f56e9025b276419578507ddbab933183649b47d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 9 Dec 2016 08:56:16 +0100 Subject: [ticket/14891] Remove unused use statements PHPBB3-14891 --- phpBB/phpbb/di/container_builder.php | 1 - phpBB/phpbb/di/proxy_instantiator.php | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 6412ccea46..4d5f189f12 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -14,7 +14,6 @@ namespace phpbb\di; use phpbb\filesystem\filesystem; -use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\FileLocator; diff --git a/phpBB/phpbb/di/proxy_instantiator.php b/phpBB/phpbb/di/proxy_instantiator.php index 28d9972cd7..1f51100493 100644 --- a/phpBB/phpbb/di/proxy_instantiator.php +++ b/phpBB/phpbb/di/proxy_instantiator.php @@ -17,7 +17,6 @@ use \bantu\IniGetWrapper\IniGetWrapper; use ProxyManager\Configuration; use ProxyManager\Factory\LazyLoadingValueHolderFactory; use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; -use ProxyManager\Proxy\LazyLoadingInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface; @@ -62,7 +61,7 @@ class proxy_instantiator implements InstantiatorInterface { return $this->factory->createProxy( $definition->getClass(), - function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) { + function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($realInstantiator) { $wrappedInstance = call_user_func($realInstantiator); $proxy->setProxyInitializer(null); -- cgit v1.2.1 From 6a568719d031544553a9e236e4128c5bfbd42600 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 9 Dec 2016 11:10:28 +0100 Subject: [ticket/14891] Use filesystem classes for checking on tmp dir The cache dir will now also only be used if tmp dir does not exist or if it's not writable. PHPBB3-14891 --- phpBB/phpbb/di/proxy_instantiator.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/proxy_instantiator.php b/phpBB/phpbb/di/proxy_instantiator.php index 1f51100493..47cc7b69c4 100644 --- a/phpBB/phpbb/di/proxy_instantiator.php +++ b/phpBB/phpbb/di/proxy_instantiator.php @@ -13,7 +13,8 @@ namespace phpbb\di; -use \bantu\IniGetWrapper\IniGetWrapper; +use bantu\IniGetWrapper\IniGetWrapper; +use phpbb\filesystem\filesystem; use ProxyManager\Configuration; use ProxyManager\Factory\LazyLoadingValueHolderFactory; use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; @@ -45,7 +46,10 @@ class proxy_instantiator implements InstantiatorInterface // Prevent trying to write to system temp dir in case of open_basedir // restrictions being in effect $ini_wrapper = new IniGetWrapper(); - if ($ini_wrapper->getString('open_basedir') || !file_exists(sys_get_temp_dir())) + $filesystem = new filesystem(); + $tmp_dir = sys_get_temp_dir(); + if ($ini_wrapper->getString('open_basedir') && + (!$filesystem->exists($tmp_dir) || !$filesystem->is_writable($tmp_dir))) { $config->setProxiesTargetDir($cache_dir); } -- cgit v1.2.1 From 90b59bb547844f6913cb459c21d249aec4226d56 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 9 Dec 2016 11:32:13 +0100 Subject: [ticket/14891] Don't rely on sys_get_temp_dir() being available Or actually returning a path. It might also return an empty string or null. PHPBB3-14891 --- phpBB/phpbb/di/proxy_instantiator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/proxy_instantiator.php b/phpBB/phpbb/di/proxy_instantiator.php index 47cc7b69c4..a388e82c0e 100644 --- a/phpBB/phpbb/di/proxy_instantiator.php +++ b/phpBB/phpbb/di/proxy_instantiator.php @@ -47,8 +47,8 @@ class proxy_instantiator implements InstantiatorInterface // restrictions being in effect $ini_wrapper = new IniGetWrapper(); $filesystem = new filesystem(); - $tmp_dir = sys_get_temp_dir(); - if ($ini_wrapper->getString('open_basedir') && + $tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : ''; + if (empty($tmp_dir) || $ini_wrapper->getString('open_basedir') && (!$filesystem->exists($tmp_dir) || !$filesystem->is_writable($tmp_dir))) { $config->setProxiesTargetDir($cache_dir); -- cgit v1.2.1 From c6aa4a319dd2cfb76a5919fc295ab782529c6646 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Dec 2016 15:04:48 +0100 Subject: [ticket/14934] Use bare PHP functions for checking for tmp dir The symfony methods will cause PHP warnings being thrown. PHPBB3-14934 --- phpBB/phpbb/di/proxy_instantiator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/proxy_instantiator.php b/phpBB/phpbb/di/proxy_instantiator.php index a388e82c0e..f8ef39535b 100644 --- a/phpBB/phpbb/di/proxy_instantiator.php +++ b/phpBB/phpbb/di/proxy_instantiator.php @@ -49,7 +49,7 @@ class proxy_instantiator implements InstantiatorInterface $filesystem = new filesystem(); $tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : ''; if (empty($tmp_dir) || $ini_wrapper->getString('open_basedir') && - (!$filesystem->exists($tmp_dir) || !$filesystem->is_writable($tmp_dir))) + (!@file_exists($tmp_dir) || !@is_writable($tmp_dir))) { $config->setProxiesTargetDir($cache_dir); } -- cgit v1.2.1 From 97b834c3ef6051f11b0f74e60fe445976fb7d681 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Dec 2016 22:19:03 +0100 Subject: [ticket/14934] Do not rely on open basedir being properly set PHPBB3-14934 --- phpBB/phpbb/di/proxy_instantiator.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/proxy_instantiator.php b/phpBB/phpbb/di/proxy_instantiator.php index f8ef39535b..70295a3dec 100644 --- a/phpBB/phpbb/di/proxy_instantiator.php +++ b/phpBB/phpbb/di/proxy_instantiator.php @@ -13,8 +13,6 @@ namespace phpbb\di; -use bantu\IniGetWrapper\IniGetWrapper; -use phpbb\filesystem\filesystem; use ProxyManager\Configuration; use ProxyManager\Factory\LazyLoadingValueHolderFactory; use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; @@ -45,11 +43,8 @@ class proxy_instantiator implements InstantiatorInterface // Prevent trying to write to system temp dir in case of open_basedir // restrictions being in effect - $ini_wrapper = new IniGetWrapper(); - $filesystem = new filesystem(); $tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : ''; - if (empty($tmp_dir) || $ini_wrapper->getString('open_basedir') && - (!@file_exists($tmp_dir) || !@is_writable($tmp_dir))) + if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir)) { $config->setProxiesTargetDir($cache_dir); } -- cgit v1.2.1 From a4d67c55d97598f29c1f5a1e6a8dec4b1e58df6d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 3 Jan 2017 22:53:18 +0100 Subject: [ticket/14957] Make sure config_php_file is set before injecting PHPBB3-14957 --- phpBB/phpbb/di/container_builder.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index a314def0f3..ac1a1a1733 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -525,6 +525,11 @@ class container_builder */ protected function inject_dbal_driver() { + if (empty($this->config_php_file)) + { + return; + } + $config_data = $this->config_php_file->get_all(); if (!empty($config_data)) { -- cgit v1.2.1 From e0d13da5f47321c9be16e93e9e1eb98d09626eed Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 17 Apr 2017 23:06:25 +0200 Subject: [ticket/15180] Adjust \phpbb\di\extension\core::TWIG_OPTIONS_POSITION PHPBB3-15180 --- phpBB/phpbb/di/extension/core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index 29c0b0e44e..67150f0103 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -24,7 +24,7 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; */ class core extends Extension { - const TWIG_OPTIONS_POSITION = 6; + const TWIG_OPTIONS_POSITION = 7; /** * Config path -- cgit v1.2.1