From cc38bf550b6d044938532d96a98dd92767e69b61 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 25 Jan 2016 13:50:23 +0100 Subject: [PATCH] [ticket/14129] Caches extensions autoloaders PHPBB3-14129 --- phpBB/phpbb/cache/driver/base.php | 1 + phpBB/phpbb/di/container_builder.php | 31 ++++++++++++++++++++++- tests/mock/phpbb_di_container_builder.php | 10 ++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/cache/driver/base.php b/phpBB/phpbb/cache/driver/base.php index 55cd4668de..85762c4d95 100644 --- a/phpBB/phpbb/cache/driver/base.php +++ b/phpBB/phpbb/cache/driver/base.php @@ -49,6 +49,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface $this->remove_dir($fileInfo->getPathname()); } else if (strpos($filename, 'container_') === 0 || + strpos($filename, 'autoload_') === 0 || strpos($filename, 'url_matcher') === 0 || strpos($filename, 'url_generator') === 0 || strpos($filename, 'sql_') === 0 || 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. * diff --git a/tests/mock/phpbb_di_container_builder.php b/tests/mock/phpbb_di_container_builder.php index 59cdf0bb2b..23dc3d1e8b 100644 --- a/tests/mock/phpbb_di_container_builder.php +++ b/tests/mock/phpbb_di_container_builder.php @@ -17,4 +17,14 @@ class phpbb_mock_phpbb_di_container_builder extends \phpbb\di\container_builder { return $this->phpbb_root_path . '../../tmp/container.' . $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->phpbb_root_path . '../../tmp/autoload.' . $this->php_ext; + } }