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/container_builder.php') 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 +++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 18 deletions(-) (limited to 'phpBB/phpbb/di/container_builder.php') 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; } /** -- 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 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/di/container_builder.php') 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) -- 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/container_builder.php') 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 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/di/container_builder.php') 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; + } } -- 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/container_builder.php') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di/container_builder.php') 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 -- 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/di/container_builder.php') 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(); -- 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/container_builder.php') 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 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/container_builder.php') 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/container_builder.php') 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/container_builder.php') 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/container_builder.php') 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 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/container_builder.php') 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 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/container_builder.php') 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/container_builder.php') 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/container_builder.php') 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/container_builder.php') 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/container_builder.php') 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/container_builder.php') 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/container_builder.php') 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/container_builder.php') 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/container_builder.php') 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 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/di/container_builder.php') 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(); -- 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/container_builder.php') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/di/container_builder.php') 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(); -- 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 - 1 file changed, 1 deletion(-) (limited to 'phpBB/phpbb/di/container_builder.php') 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; -- 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/container_builder.php') 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