[ticket/14129] Caches extensions autoloaders

PHPBB3-14129
This commit is contained in:
Tristan Darricau 2016-01-25 13:50:23 +01:00
parent 56062a2635
commit cc38bf550b
3 changed files with 41 additions and 1 deletions

View file

@ -49,6 +49,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
$this->remove_dir($fileInfo->getPathname()); $this->remove_dir($fileInfo->getPathname());
} }
else if (strpos($filename, 'container_') === 0 || else if (strpos($filename, 'container_') === 0 ||
strpos($filename, 'autoload_') === 0 ||
strpos($filename, 'url_matcher') === 0 || strpos($filename, 'url_matcher') === 0 ||
strpos($filename, 'url_generator') === 0 || strpos($filename, 'url_generator') === 0 ||
strpos($filename, 'sql_') === 0 || strpos($filename, 'sql_') === 0 ||

View file

@ -135,6 +135,11 @@ class container_builder
$config_cache = new ConfigCache($container_filename, defined('DEBUG')); $config_cache = new ConfigCache($container_filename, defined('DEBUG'));
if ($this->use_cache && $config_cache->isFresh()) if ($this->use_cache && $config_cache->isFresh())
{ {
if ($this->use_extensions)
{
require($this->get_autoload_filename());
}
require($config_cache->getPath()); require($config_cache->getPath());
$this->container = new \phpbb_cache_container(); $this->container = new \phpbb_cache_container();
} }
@ -405,6 +410,15 @@ class container_builder
$extensions = $ext_container->get('ext.manager')->all_enabled(); $extensions = $ext_container->get('ext.manager')->all_enabled();
// Load each extension found // 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) foreach ($extensions as $ext_name => $path)
{ {
$extension_class = '\\' . str_replace('/', '\\', $ext_name) . '\\di\\extension'; $extension_class = '\\' . str_replace('/', '\\', $ext_name) . '\\di\\extension';
@ -420,9 +434,14 @@ class container_builder
$filename = $path . 'vendor/autoload.php'; $filename = $path . 'vendor/autoload.php';
if (file_exists($filename)) 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 else
{ {
@ -539,6 +558,16 @@ class container_builder
return $this->get_cache_dir() . 'container_' . md5($this->phpbb_root_path) . '.' . $this->php_ext; 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. * Return the name of the current environment.
* *

View file

@ -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; 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;
}
} }