From 897e8f2e8361839a92acae7e77225ef212e44647 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 9 Nov 2012 23:00:44 +0100 Subject: [ticket/11152] Move container functions to a separate function file PHPBB3-11152 --- phpBB/includes/functions_container.php | 119 +++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 phpBB/includes/functions_container.php (limited to 'phpBB/includes/functions_container.php') diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php new file mode 100644 index 0000000000..88adc64882 --- /dev/null +++ b/phpBB/includes/functions_container.php @@ -0,0 +1,119 @@ +registerExtension($extension); + $container->loadFromExtension($extension->getAlias()); + } + + $container->setParameter('core.root_path', $phpbb_root_path); + $container->setParameter('core.php_ext', $php_ext); + + return $container; +} + +/** +* Create installer container +* +* @param string $phpbb_root_path Root path +* @param string $php_ext PHP Extension +* @return ContainerBuilder object +*/ +function phpbb_create_install_container($phpbb_root_path, $php_ext) +{ + // We have to do it like this instead of with extensions + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); + $loader->load('services.yml'); + + $container->setParameter('core.root_path', $phpbb_root_path); + $container->setParameter('core.php_ext', $php_ext); + + $container->setAlias('cache.driver', 'cache.driver.install'); + + return $container; +} + +/** +* Create a compiled ContainerBuilder object +* +* @param array $extensions Array of Container extension objects +* @param array $passes Array of Compiler Pass objects +* @param string $phpbb_root_path Root path +* @param string $php_ext PHP Extension +* @return ContainerBuilder object (compiled) +*/ +function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $php_ext) +{ + // Check for our cached container; if it exists, use it + if (file_exists("{$phpbb_root_path}cache/container.$php_ext")) + { + require("{$phpbb_root_path}cache/container.$php_ext"); + return new phpbb_cache_container(); + } + + // We must use an absolute path in the container because we cannot + // change the value at runtime when accessing it in different + // directory levels. + $phpbb_absolute_path = phpbb_realpath($phpbb_root_path) . '/'; + + // Create a temporary container for access to the ext.manager service + $tmp_container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext); + $tmp_container->compile(); + + // Now pass the enabled extension paths into the ext compiler extension + $extensions[] = new phpbb_di_extension_ext($tmp_container->get('ext.manager')->all_enabled()); + + // Create the final container to be compiled and cached + $container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext); + + // Compile the container + foreach ($passes as $pass) + { + $container->addCompilerPass($pass); + } + $container->compile(); + + // Lastly, we create our cached container class + $dumper = new PhpDumper($container); + $cached_container_dump = $dumper->dump(array( + 'class' => 'phpbb_cache_container', + 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', + )); + + $file = file_put_contents("{$phpbb_absolute_path}cache/container.{$php_ext}", $cached_container_dump); + + return $container; +} -- cgit v1.2.1 From 38e1c4ec5d363900285a6a72ee78f4f2e2943bd0 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 09:55:17 +0100 Subject: [ticket/11152] Use relative root path in container, one dumped container per path PHPBB3-11152 --- phpBB/includes/functions_container.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions_container.php') diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index 88adc64882..8e2c9606cd 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -78,26 +78,22 @@ function phpbb_create_install_container($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 - if (file_exists("{$phpbb_root_path}cache/container.$php_ext")) + $container_filename = phpbb_container_filename($phpbb_root_path, $php_ext); + if (file_exists($container_filename)) { - require("{$phpbb_root_path}cache/container.$php_ext"); + require($container_filename); return new phpbb_cache_container(); } - // We must use an absolute path in the container because we cannot - // change the value at runtime when accessing it in different - // directory levels. - $phpbb_absolute_path = phpbb_realpath($phpbb_root_path) . '/'; - // Create a temporary container for access to the ext.manager service - $tmp_container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext); + $tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); $tmp_container->compile(); // Now pass the enabled extension paths into the ext compiler extension $extensions[] = new phpbb_di_extension_ext($tmp_container->get('ext.manager')->all_enabled()); // Create the final container to be compiled and cached - $container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext); + $container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); // Compile the container foreach ($passes as $pass) @@ -113,7 +109,13 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', )); - $file = file_put_contents("{$phpbb_absolute_path}cache/container.{$php_ext}", $cached_container_dump); + file_put_contents($container_filename, $cached_container_dump); return $container; } + +function phpbb_container_filename($phpbb_root_path, $php_ext) +{ + $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); + return $phpbb_root_path . 'cache/' . $filename . '_container.' . $php_ext; +} -- cgit v1.2.1 From 8851b797fbf0f1b4120aa4d3ae713711e01ef98f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 23:35:52 +0100 Subject: [ticket/11152] Create separate function for debug-dependent container PHPBB3-11152 --- phpBB/includes/functions_container.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/functions_container.php') diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index 8e2c9606cd..e31fe381ac 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -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) { - // 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 $tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); $tmp_container->compile(); @@ -102,6 +94,21 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb } $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 $dumper = new PhpDumper($container); $cached_container_dump = $dumper->dump(array( @@ -114,6 +121,15 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb 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) { $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); -- cgit v1.2.1 From 00417fc723073a9e8acefe4a8a7660bf25017201 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 17:54:54 +0100 Subject: [ticket/11152] Compile the install container PHPBB3-11152 --- phpBB/includes/functions_container.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_container.php') diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index e31fe381ac..1de1d9f7ea 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -53,16 +53,19 @@ function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext) */ function phpbb_create_install_container($phpbb_root_path, $php_ext) { - // We have to do it like this instead of with extensions - $container = new ContainerBuilder(); - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); - $loader->load('services.yml'); + $core = new phpbb_di_extension_core($phpbb_root_path); + $container = phpbb_create_container(array($core), $phpbb_root_path, $php_ext); $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $php_ext); + $container->setParameter('core.table_prefix', ''); + + $container->register('dbal.conn')->setSynthetic(true); $container->setAlias('cache.driver', 'cache.driver.install'); + $container->compile(); + return $container; } -- cgit v1.2.1