[ticket/11152] Create separate function for debug-dependent container

PHPBB3-11152
This commit is contained in:
Igor Wiedler 2012-11-10 23:35:52 +01:00
parent 231d743ba9
commit 8851b797fb
4 changed files with 27 additions and 11 deletions

View file

@ -100,7 +100,7 @@ $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_pat
$phpbb_class_loader_ext->register(); $phpbb_class_loader_ext->register();
// Set up container // Set up container
$phpbb_container = phpbb_create_compiled_container( $phpbb_container = phpbb_create_dumped_container_unless_debug(
array( array(
new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx),
new phpbb_di_extension_core($phpbb_root_path), new phpbb_di_extension_core($phpbb_root_path),

View file

@ -59,7 +59,7 @@ if (isset($_GET['avatar']))
$phpbb_class_loader_ext->register(); $phpbb_class_loader_ext->register();
// Set up container // Set up container
$phpbb_container = phpbb_create_compiled_container( $phpbb_container = phpbb_create_dumped_container_unless_debug(
array( array(
new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx),
new phpbb_di_extension_core($phpbb_root_path), new phpbb_di_extension_core($phpbb_root_path),

View file

@ -77,14 +77,6 @@ function phpbb_create_install_container($phpbb_root_path, $php_ext)
*/ */
function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $php_ext) function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $php_ext)
{ {
// Check for our cached container; if it exists, use it
$container_filename = phpbb_container_filename($phpbb_root_path, $php_ext);
if (file_exists($container_filename))
{
require($container_filename);
return new phpbb_cache_container();
}
// Create a temporary container for access to the ext.manager service // Create a temporary container for access to the ext.manager service
$tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); $tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext);
$tmp_container->compile(); $tmp_container->compile();
@ -102,6 +94,21 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb
} }
$container->compile(); $container->compile();
return $container;
}
function phpbb_create_dumped_container(array $extensions, array $passes, $phpbb_root_path, $php_ext)
{
// Check for our cached container; if it exists, use it
$container_filename = phpbb_container_filename($phpbb_root_path, $php_ext);
if (file_exists($container_filename))
{
require($container_filename);
return new phpbb_cache_container();
}
$container = phpbb_create_compiled_container($extensions, $passes, $phpbb_root_path, $php_ext);
// Lastly, we create our cached container class // Lastly, we create our cached container class
$dumper = new PhpDumper($container); $dumper = new PhpDumper($container);
$cached_container_dump = $dumper->dump(array( $cached_container_dump = $dumper->dump(array(
@ -114,6 +121,15 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb
return $container; return $container;
} }
function phpbb_create_dumped_container_unless_debug(array $extensions, array $passes, $phpbb_root_path, $php_ext)
{
if (defined('DEBUG')) {
return phpbb_create_compiled_container($extensions, $passes, $phpbb_root_path, $php_ext);
}
return phpbb_create_dumped_container($extensions, $passes, $phpbb_root_path, $php_ext);
}
function phpbb_container_filename($phpbb_root_path, $php_ext) function phpbb_container_filename($phpbb_root_path, $php_ext)
{ {
$filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path);

View file

@ -117,7 +117,7 @@ $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_pat
$phpbb_class_loader_ext->register(); $phpbb_class_loader_ext->register();
// Set up container // Set up container
$phpbb_container = phpbb_create_compiled_container( $phpbb_container = phpbb_create_dumped_container_unless_debug(
array( array(
new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx),
new phpbb_di_extension_core($phpbb_root_path), new phpbb_di_extension_core($phpbb_root_path),