diff options
author | Marc Alexander <admin@m-a-styles.de> | 2016-01-27 10:44:47 +0100 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2016-01-27 10:44:47 +0100 |
commit | b8b419704c509c62c8008f28521d7eb54d262360 (patch) | |
tree | 35e48a7d05bcc6d9a16aac1d2267584e99090491 | |
parent | ad914a68807e3bf3335614a09414635eb932f147 (diff) | |
parent | cc38bf550b6d044938532d96a98dd92767e69b61 (diff) | |
download | forums-b8b419704c509c62c8008f28521d7eb54d262360.tar forums-b8b419704c509c62c8008f28521d7eb54d262360.tar.gz forums-b8b419704c509c62c8008f28521d7eb54d262360.tar.bz2 forums-b8b419704c509c62c8008f28521d7eb54d262360.tar.xz forums-b8b419704c509c62c8008f28521d7eb54d262360.zip |
Merge pull request #4142 from Nicofuma/ticket/14129
[ticket/14129] Caches extensions autoloaders
-rw-r--r-- | phpBB/phpbb/cache/driver/base.php | 1 | ||||
-rw-r--r-- | phpBB/phpbb/di/container_builder.php | 31 | ||||
-rw-r--r-- | tests/mock/phpbb_di_container_builder.php | 10 |
3 files changed, 41 insertions, 1 deletions
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 = '<?php +/** + * Loads all extensions custom auto-loaders. + * + * This file has been auto-generated + * by phpBB while loading the extensions. + */ + +'; foreach ($extensions as $ext_name => $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 { @@ -540,6 +559,16 @@ class container_builder } /** + * 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. * * @return string 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; + } } |