Skip to content

Commit

Permalink
[ticket/14129] Caches extensions autoloaders
Browse files Browse the repository at this point in the history
PHPBB3-14129
  • Loading branch information
Tristan Darricau committed Jan 26, 2016
1 parent 56062a2 commit cc38bf5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions phpBB/phpbb/cache/driver/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function purge()
$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 ||
Expand Down
31 changes: 30 additions & 1 deletion phpBB/phpbb/di/container_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public function get_container()
$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();
}
Expand Down Expand Up @@ -405,6 +410,15 @@ protected function load_extensions()
$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';
Expand All @@ -420,9 +434,14 @@ protected function load_extensions()
$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
{
Expand Down Expand Up @@ -539,6 +558,16 @@ protected function get_container_filename()
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.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/mock/phpbb_di_container_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ protected function get_container_filename()
{
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;
}
}

0 comments on commit cc38bf5

Please sign in to comment.