From f48709f5bb8fb1b916d308e3b4bb06bc96d08611 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 19 Oct 2012 19:53:29 -0400 Subject: [PATCH 01/29] [feature/compiled-dic] Compile the DI Container into a cached class PHPBB3-11152 --- phpBB/common.php | 39 +++-- phpBB/config/services.yml | 4 +- phpBB/download/file.php | 27 ++- phpBB/includes/cache/driver/file.php | 2 +- phpBB/includes/cache/driver/memory.php | 2 +- .../di/{processor => extension}/config.php | 61 ++++--- phpBB/includes/di/extension/core.php | 76 +++++++++ phpBB/includes/di/extension/ext.php | 73 ++++++++ phpBB/includes/di/processor/ext.php | 54 ------ phpBB/includes/di/processor/interface.php | 28 --- phpBB/includes/event/dispatcher.php | 4 +- phpBB/includes/event/kernel_compiler_pass.php | 72 ++++++++ phpBB/includes/event/kernel_subscriber.php | 94 ++++++++++ phpBB/includes/extension/controller.php | 84 --------- .../extension/controller_interface.php | 31 ---- phpBB/includes/functions.php | 102 +++++++++++ phpBB/install/database_update.php | 34 ++-- phpBB/install/index.php | 16 +- tests/event/dispatcher_test.php | 2 +- tests/mock/container_builder.php | 160 ++++++++++++++++++ 20 files changed, 692 insertions(+), 273 deletions(-) rename phpBB/includes/di/{processor => extension}/config.php (52%) create mode 100644 phpBB/includes/di/extension/core.php create mode 100644 phpBB/includes/di/extension/ext.php delete mode 100644 phpBB/includes/di/processor/ext.php delete mode 100644 phpBB/includes/di/processor/interface.php create mode 100644 phpBB/includes/event/kernel_compiler_pass.php create mode 100644 phpBB/includes/event/kernel_subscriber.php delete mode 100644 phpBB/includes/extension/controller.php delete mode 100644 phpBB/includes/extension/controller_interface.php create mode 100644 tests/mock/container_builder.php diff --git a/phpBB/common.php b/phpBB/common.php index 6943b02fa0..a681561619 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -81,8 +81,6 @@ if (!empty($load_extensions) && function_exists('dl')) // Include files require($phpbb_root_path . 'includes/class_loader.' . $phpEx); -require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx); -require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); @@ -94,16 +92,28 @@ require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); -$phpbb_container = new ContainerBuilder(); -$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config')); -$loader->load('services.yml'); - -$processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); -$processor->process($phpbb_container); - // Setup class loader first -$phpbb_class_loader = $phpbb_container->get('class_loader'); -$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); +$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", ".$phpEx"); +$phpbb_class_loader->register(); +$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", ".$phpEx"); +$phpbb_class_loader_ext->register(); + +// Set up container +$phpbb_container = phpbb_create_compiled_container( + array( + new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), + new phpbb_di_extension_core($phpbb_root_path), + ), + array( + new phpbb_event_kernel_compiler_pass(), + ), + $phpbb_root_path . 'config.' . $phpEx, + $phpbb_root_path, + $phpEx +); + +$phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); +$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); // set up caching $cache = $phpbb_container->get('cache'); @@ -130,13 +140,6 @@ $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); $template = $phpbb_container->get('template'); $phpbb_style = $phpbb_container->get('style'); -$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); -foreach ($ids as $id) -{ - $processor = $phpbb_container->get($id); - $processor->process($phpbb_container); -} - // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'display'))); diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 038c8a862d..6c904ac2c8 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -47,7 +47,7 @@ services: cron.task_provider: class: phpbb_cron_task_provider arguments: - - @container + - @service_container cron.manager: class: phpbb_cron_manager @@ -65,6 +65,8 @@ services: dispatcher: class: phpbb_event_dispatcher + arguments: + - @service_container dbal.conn: class: %dbal.driver.class% diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 7ed53d54b6..85dc8acb81 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -51,15 +51,28 @@ if (isset($_GET['avatar'])) require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); - $phpbb_container = new ContainerBuilder(); - $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); - $loader->load('services.yml'); + // Setup class loader first + $phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", ".$phpEx"); + $phpbb_class_loader->register(); + $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", ".$phpEx"); + $phpbb_class_loader_ext->register(); - $processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); - $processor->process($phpbb_container); + // Set up container + $phpbb_container = phpbb_create_compiled_container( + array( + new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), + new phpbb_di_extension_core($phpbb_root_path), + ), + array( + new phpbb_event_kernel_compiler_pass(), + ), + $phpbb_root_path . 'config.' . $phpEx, + $phpbb_root_path, + $phpEx + ); - $phpbb_class_loader = $phpbb_container->get('class_loader'); - $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); + $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); + $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); // set up caching $cache = $phpbb_container->get('cache'); diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index f64a9e3ea8..b8876b03b4 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -214,7 +214,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0) + if (strpos($entry, 'container') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0) { continue; } diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index e0771ab1d3..9ee32fff28 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -162,7 +162,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0) + if (strpos($entry, 'container') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0) { continue; } diff --git a/phpBB/includes/di/processor/config.php b/phpBB/includes/di/extension/config.php similarity index 52% rename from phpBB/includes/di/processor/config.php rename to phpBB/includes/di/extension/config.php index 22b6252a6d..b9c752c5de 100644 --- a/phpBB/includes/di/processor/config.php +++ b/phpBB/includes/di/extension/config.php @@ -16,40 +16,33 @@ if (!defined('IN_PHPBB')) } use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\Config\FileLocator; /** -* Configure the container for phpBB's services though -* user-defined parameters defined in the config.php file. +* Container config extension */ -class phpbb_di_processor_config implements phpbb_di_processor_interface +class phpbb_di_extension_config extends Extension { - private $config_file; - private $phpbb_root_path; - private $php_ext; - - /** - * Constructor. - * - * @param string $config_file The config file - * @param string $phpbb_root_path The root path - * @param string $php_ext The PHP extension - */ - public function __construct($config_file, $phpbb_root_path, $php_ext) + public function __construct($config_file) { $this->config_file = $config_file; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; } /** - * @inheritdoc + * Loads a specific configuration. + * + * @param array $config An array of configuration values + * @param ContainerBuilder $container A ContainerBuilder instance + * + * @throws InvalidArgumentException When provided tag is not defined in this extension + * + * @api */ - public function process(ContainerBuilder $container) + public function load(array $config, ContainerBuilder $container) { - require $this->config_file; - - $container->setParameter('core.root_path', $this->phpbb_root_path); - $container->setParameter('core.php_ext', $this->php_ext); + require($this->config_file); $container->setParameter('core.table_prefix', $table_prefix); $container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); @@ -60,10 +53,28 @@ class phpbb_di_processor_config implements phpbb_di_processor_interface $container->setParameter('dbal.dbname', $dbname); $container->setParameter('dbal.dbport', $dbport); $container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); - - $container->set('container', $container); } + /** + * Returns the recommended alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * @return string The alias + * + * @api + */ + public function getAlias() + { + return 'config'; + } + + /** + * Convert old (3.0) values to 3.1 class names + * + * @param style $acm_type ACM type + * @return ACM type class + */ protected function fix_acm_type($acm_type) { if (preg_match('#^[a-z]+$#', $acm_type)) diff --git a/phpBB/includes/di/extension/core.php b/phpBB/includes/di/extension/core.php new file mode 100644 index 0000000000..26aa325bdd --- /dev/null +++ b/phpBB/includes/di/extension/core.php @@ -0,0 +1,76 @@ +phpbb_root_path = $phpbb_root_path; + } + + /** + * Loads a specific configuration. + * + * @param array $config An array of configuration values + * @param ContainerBuilder $container A ContainerBuilder instance + * + * @throws InvalidArgumentException When provided tag is not defined in this extension + * + * @api + */ + public function load(array $config, ContainerBuilder $container) + { + if (file_exists($this->phpbb_root_path . 'config/services.yml')) + { + $loader = new YamlFileLoader($container, new FileLocator(realpath($this->phpbb_root_path . 'config'))); + $loader->load('services.yml'); + } + } + + /** + * Returns the recommended alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * @return string The alias + * + * @api + */ + public function getAlias() + { + return 'core'; + } +} diff --git a/phpBB/includes/di/extension/ext.php b/phpBB/includes/di/extension/ext.php new file mode 100644 index 0000000000..2539ff5667 --- /dev/null +++ b/phpBB/includes/di/extension/ext.php @@ -0,0 +1,73 @@ + $path) + { + $this->paths[] = $path; + } + } + + /** + * Loads a specific configuration. + * + * @param array $config An array of configuration values + * @param ContainerBuilder $container A ContainerBuilder instance + * + * @throws InvalidArgumentException When provided tag is not defined in this extension + * + * @api + */ + public function load(array $config, ContainerBuilder $container) + { + foreach ($this->paths as $path) + { + if (file_exists($path . '/config/services.yml')) + { + $loader = new YamlFileLoader($container, new FileLocator($path . '/config')); + $loader->load('services.yml'); + } + } + } + + /** + * Returns the recommended alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * @return string The alias + * + * @api + */ + public function getAlias() + { + return 'ext'; + } +} diff --git a/phpBB/includes/di/processor/ext.php b/phpBB/includes/di/processor/ext.php deleted file mode 100644 index e69a3d73b3..0000000000 --- a/phpBB/includes/di/processor/ext.php +++ /dev/null @@ -1,54 +0,0 @@ -extension_manager = $extension_manager; - } - - /** - * @inheritdoc - */ - public function process(ContainerBuilder $container) - { - $enabled_exts = $this->extension_manager->all_enabled(); - foreach ($enabled_exts as $name => $path) - { - if (file_exists($path . '/config/services.yml')) - { - $loader = new YamlFileLoader($container, new FileLocator($path . '/config')); - $loader->load('services.yml'); - } - } - } -} diff --git a/phpBB/includes/di/processor/interface.php b/phpBB/includes/di/processor/interface.php deleted file mode 100644 index b8563791cc..0000000000 --- a/phpBB/includes/di/processor/interface.php +++ /dev/null @@ -1,28 +0,0 @@ -trigger_event('core.index', compact($vars))); * */ -class phpbb_event_dispatcher extends EventDispatcher +class phpbb_event_dispatcher extends ContainerAwareEventDispatcher { public function trigger_event($eventName, $data = array()) { diff --git a/phpBB/includes/event/kernel_compiler_pass.php b/phpBB/includes/event/kernel_compiler_pass.php new file mode 100644 index 0000000000..18b6661cd4 --- /dev/null +++ b/phpBB/includes/event/kernel_compiler_pass.php @@ -0,0 +1,72 @@ +getDefinition('dispatcher'); + $user = $container->get('user'); + + foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) + { + foreach ($events as $event) + { + $priority = isset($event['priority']) ? $event['priority'] : 0; + + if (!isset($event['event'])) + { + throw new InvalidArgumentException($user->lang('NO_EVENT_ATTRIBUTE', $id)); + } + + if (!isset($event['method'])) + { + $event['method'] = 'on'.preg_replace(array( + '/(?<=\b)[a-z]/ie', + '/[^a-z0-9]/i' + ), array('strtoupper("\\0")', ''), $event['event']); + } + + $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); + } + } + + foreach ($container->findTaggedServiceIds('kernel.event_subscriber') as $id => $attributes) + { + // We must assume that the class value has been correctly filled, even if the service is created by a factory + $class = $container->getDefinition($id)->getClass(); + + $refClass = new ReflectionClass($class); + $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; + if (!$refClass->implementsInterface($interface)) + { + throw new InvalidArgumentException($user->lang('SUBSCRIBER_WRONG_TYPE', $id, $interface)); + } + + $definition->addMethodCall('addSubscriberService', array($id, $class)); + } + } +} diff --git a/phpBB/includes/event/kernel_subscriber.php b/phpBB/includes/event/kernel_subscriber.php new file mode 100644 index 0000000000..9737d9bc23 --- /dev/null +++ b/phpBB/includes/event/kernel_subscriber.php @@ -0,0 +1,94 @@ +template = $template; + $this->user = $user; + } + + /** + * This listener is run when the KernelEvents::TERMINATE event is triggered + * This comes after a Response has been sent to the server; this is + * primarily cleanup stuff. + * + * @param PostResponseEvent $event + * @return null + */ + public function on_kernel_terminate(PostResponseEvent $event) + { + exit_handler(); + } + + /** + * This listener is run when the KernelEvents::EXCEPTION event is triggered + * + * @param GetResponseForExceptionEvent $event + * @return null + */ + public function on_kernel_exception(GetResponseForExceptionEvent $event) + { + page_header($this->user->lang('INFORMATION')); + + $this->template->assign_vars(array( + 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), + 'MESSAGE_TEXT' => $event->getException()->getMessage(), + )); + + $this->template->set_filenames(array( + 'body' => 'message_body.html', + )); + + page_footer(true, false, false); + + $event->setResponse(new Response($this->template->return_display('body'), 404)); + } + + public static function getSubscribedEvents() + { + return array( + KernelEvents::TERMINATE => 'on_kernel_terminate', + KernelEvents::EXCEPTION => 'on_kernel_exception', + ); + } +} diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php deleted file mode 100644 index f97b69c7ed..0000000000 --- a/phpBB/includes/extension/controller.php +++ /dev/null @@ -1,84 +0,0 @@ -request = $request; - $this->db = $db; - $this->user = $user; - $this->template = $template; - $this->config = $config; - $this->php_ext = $phpEx; - $this->phpbb_root_path = $phpbb_root_path; - } -} diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php deleted file mode 100644 index 2b88925388..0000000000 --- a/phpBB/includes/extension/controller_interface.php +++ /dev/null @@ -1,31 +0,0 @@ - PHP_INT_MAX) ? (float) $input : (int) $input; } + +/** +* Create the ContainerBuilder object +* +* @param array $extensions Array of Container extension objects +* @param string $phpbb_root_path Root path +* @param string $phpEx PHP Extension +* @return ContainerBuilder object +*/ +function phpbb_create_container(array $extensions, $phpbb_root_path, $phpEx) +{ + $container = new ContainerBuilder(); + + foreach ($extensions as $extension) + { + $container->registerExtension($extension); + $container->loadFromExtension($extension->getAlias()); + } + + $container->set('container', $container); + $container->setParameter('core.root_path', $phpbb_root_path); + $container->setParameter('core.php_ext', $phpEx); + + return $container; +} + +/** +* Create installer container +* +* @param string $phpbb_root_path Root path +* @param string $phpEx PHP Extension +* @return ContainerBuilder object +*/ +function phpbb_create_install_container($phpbb_root_path, $phpEx) +{ + // 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', $phpEx); + + $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 $phpEx PHP Extension +* @return ContainerBuilder object (compiled) +*/ +function phpbb_create_compiled_container(array $extensions, array $passes, $config_file_path, $phpbb_root_path, $phpEx) +{ + // Check for our cached container; if it exists, use it + if (file_exists("{$phpbb_root_path}cache/container.$phpEx")) + { + require("{$phpbb_root_path}cache/container.$phpEx"); + return new phpbb_cache_container(); + } + + // If we don't have the cached container class, we make it now + // First, we create the temporary container so we can access the + // extension_manager + $tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $phpEx); + $tmp_container->compile(); + + // Now we pass the enabled extension paths into the ext compiler extension + $extensions[] = new phpbb_di_extension_ext($tmp_container->get('ext.manager')->all_enabled()); + + // And create our final container + $container = phpbb_create_container($extensions, $phpbb_root_path, $phpEx); + + 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_root_path}cache/container.$phpEx", $cached_container_dump); + + return $container; +} diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 527108af08..65c72ad635 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -109,20 +109,28 @@ if (!defined('EXT_TABLE')) define('EXT_TABLE', $table_prefix . 'ext'); } -$phpbb_container = new ContainerBuilder(); -$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); -$loader->load('services.yml'); - -// We must include the DI processor class files because the class loader -// is not yet set up -require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx); -require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx); -$processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); -$processor->process($phpbb_container); - // Setup class loader first -$phpbb_class_loader = $phpbb_container->get('class_loader'); -$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); +$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", ".$phpEx"); +$phpbb_class_loader->register(); +$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", ".$phpEx"); +$phpbb_class_loader_ext->register(); + +// Set up container +$phpbb_container = phpbb_create_compiled_container( + array( + new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), + new phpbb_di_extension_core($phpbb_root_path), + ), + array( + new phpbb_event_kernel_compiler_pass(), + ), + $phpbb_root_path . 'config.' . $phpEx, + $phpbb_root_path, + $phpEx +); + +$phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); +$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); // set up caching $cache = $phpbb_container->get('cache'); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index f71e5ada54..9203a7d3bc 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -75,8 +75,6 @@ else // Include essential scripts require($phpbb_root_path . 'includes/class_loader.' . $phpEx); -require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx); -require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); @@ -86,14 +84,18 @@ include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/functions_install.' . $phpEx); -$phpbb_container = new ContainerBuilder(); -$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); -$loader->load('services.yml'); +// Setup class loader first +$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", ".$phpEx"); +$phpbb_class_loader->register(); +$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_path}ext/", ".$phpEx"); +$phpbb_class_loader_ext->register(); -$phpbb_container->setParameter('core.root_path', $phpbb_root_path); -$phpbb_container->setParameter('core.php_ext', $phpEx); +// Set up container +$phpbb_container = phpbb_create_install_container($phpbb_root_path, $phpEx); $phpbb_container->setAlias('cache.driver', 'cache.driver.install'); +$phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); +$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); diff --git a/tests/event/dispatcher_test.php b/tests/event/dispatcher_test.php index f8fe060d99..9b9203e06a 100644 --- a/tests/event/dispatcher_test.php +++ b/tests/event/dispatcher_test.php @@ -11,7 +11,7 @@ class phpbb_event_dispatcher_test extends phpbb_test_case { public function test_trigger_event() { - $dispatcher = new phpbb_event_dispatcher(); + $dispatcher = new phpbb_event_dispatcher(new phpbb_mock_container_builder()); $dispatcher->addListener('core.test_event', function (phpbb_event_data $event) { $event['foo'] = $event['foo'] . '2'; diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php new file mode 100644 index 0000000000..8a81dd72d1 --- /dev/null +++ b/tests/mock/container_builder.php @@ -0,0 +1,160 @@ + Date: Sat, 20 Oct 2012 10:23:04 -0400 Subject: [PATCH 02/29] [feature/compiled-dic] Split if() over multiple lines for improved readability PHPBB3-11152 --- phpBB/includes/cache/driver/file.php | 6 +++++- phpBB/includes/cache/driver/memory.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index b8876b03b4..b20c0064ea 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -214,7 +214,11 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'container') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0) + if (strpos($entry, 'container') !== 0 && + strpos($entry, 'sql_') !== 0 && + strpos($entry, 'data_') !== 0 && + strpos($entry, 'ctpl_') !== 0 && + strpos($entry, 'tpl_') !== 0) { continue; } diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index 9ee32fff28..98ac02b161 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -162,7 +162,11 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'container') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0) + if (strpos($entry, 'container') !== 0 && + strpos($entry, 'sql_') !== 0 && + strpos($entry, 'data_') !== 0 && + strpos($entry, 'ctpl_') !== 0 && + strpos($entry, 'tpl_') !== 0) { continue; } From 2f692ef3b9bf87375f1e0922f8f42a595bda9d88 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 10:34:42 -0400 Subject: [PATCH 03/29] [feature/compiled-dic] Remove redundant method call PHPBB3-11152 --- phpBB/install/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 9203a7d3bc..9d8e9e87aa 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -93,7 +93,6 @@ $phpbb_class_loader_ext->register(); // Set up container $phpbb_container = phpbb_create_install_container($phpbb_root_path, $phpEx); -$phpbb_container->setAlias('cache.driver', 'cache.driver.install'); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); From 996f63fb34de9f631374fb4b3fb0fb14598affa4 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 10:36:09 -0400 Subject: [PATCH 04/29] [feature/compiled-dic] Remove re-creation of class loader in install PHPBB3-11152 --- phpBB/install/index.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 9d8e9e87aa..0afa24066a 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -96,9 +96,6 @@ $phpbb_container = phpbb_create_install_container($phpbb_root_path, $phpEx); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); -$phpbb_class_loader = $phpbb_container->get('class_loader'); -$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); - // set up caching $cache = $phpbb_container->get('cache'); From d88e11413ac89ac2bfda303dd4ecaacef6dc8c0f Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 10:46:38 -0400 Subject: [PATCH 05/29] [feature/compiled-dic] Remove unused service definition PHPBB3-11152 --- phpBB/includes/functions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 72c5a26bd5..d724374744 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5438,7 +5438,6 @@ function phpbb_create_container(array $extensions, $phpbb_root_path, $phpEx) $container->loadFromExtension($extension->getAlias()); } - $container->set('container', $container); $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $phpEx); From 6d40b81dda242f5f07fe1e01430d70e6879d1885 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 10:58:35 -0400 Subject: [PATCH 06/29] [feature/compiled-dic] Remove unused function parameter PHPBB3-11152 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index d724374744..ac63bd086c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5475,7 +5475,7 @@ function phpbb_create_install_container($phpbb_root_path, $phpEx) * @param string $phpEx PHP Extension * @return ContainerBuilder object (compiled) */ -function phpbb_create_compiled_container(array $extensions, array $passes, $config_file_path, $phpbb_root_path, $phpEx) +function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $phpEx) { // Check for our cached container; if it exists, use it if (file_exists("{$phpbb_root_path}cache/container.$phpEx")) From b20d852b7fc43431ade40ee97fd5ece5e3271d5d Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 16:57:21 -0400 Subject: [PATCH 07/29] [feature/compiled-dic] Remove HttpKernel-related stuff These things should be added in the Controller PR instead. PHPBB3-11152 --- phpBB/common.php | 4 +- phpBB/includes/event/kernel_compiler_pass.php | 72 -------------- phpBB/includes/event/kernel_subscriber.php | 94 ------------------- 3 files changed, 1 insertion(+), 169 deletions(-) delete mode 100644 phpBB/includes/event/kernel_compiler_pass.php delete mode 100644 phpBB/includes/event/kernel_subscriber.php diff --git a/phpBB/common.php b/phpBB/common.php index a681561619..fce08f3834 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -104,9 +104,7 @@ $phpbb_container = phpbb_create_compiled_container( new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_core($phpbb_root_path), ), - array( - new phpbb_event_kernel_compiler_pass(), - ), + array(), $phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx diff --git a/phpBB/includes/event/kernel_compiler_pass.php b/phpBB/includes/event/kernel_compiler_pass.php deleted file mode 100644 index 18b6661cd4..0000000000 --- a/phpBB/includes/event/kernel_compiler_pass.php +++ /dev/null @@ -1,72 +0,0 @@ -getDefinition('dispatcher'); - $user = $container->get('user'); - - foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) - { - foreach ($events as $event) - { - $priority = isset($event['priority']) ? $event['priority'] : 0; - - if (!isset($event['event'])) - { - throw new InvalidArgumentException($user->lang('NO_EVENT_ATTRIBUTE', $id)); - } - - if (!isset($event['method'])) - { - $event['method'] = 'on'.preg_replace(array( - '/(?<=\b)[a-z]/ie', - '/[^a-z0-9]/i' - ), array('strtoupper("\\0")', ''), $event['event']); - } - - $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); - } - } - - foreach ($container->findTaggedServiceIds('kernel.event_subscriber') as $id => $attributes) - { - // We must assume that the class value has been correctly filled, even if the service is created by a factory - $class = $container->getDefinition($id)->getClass(); - - $refClass = new ReflectionClass($class); - $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; - if (!$refClass->implementsInterface($interface)) - { - throw new InvalidArgumentException($user->lang('SUBSCRIBER_WRONG_TYPE', $id, $interface)); - } - - $definition->addMethodCall('addSubscriberService', array($id, $class)); - } - } -} diff --git a/phpBB/includes/event/kernel_subscriber.php b/phpBB/includes/event/kernel_subscriber.php deleted file mode 100644 index 9737d9bc23..0000000000 --- a/phpBB/includes/event/kernel_subscriber.php +++ /dev/null @@ -1,94 +0,0 @@ -template = $template; - $this->user = $user; - } - - /** - * This listener is run when the KernelEvents::TERMINATE event is triggered - * This comes after a Response has been sent to the server; this is - * primarily cleanup stuff. - * - * @param PostResponseEvent $event - * @return null - */ - public function on_kernel_terminate(PostResponseEvent $event) - { - exit_handler(); - } - - /** - * This listener is run when the KernelEvents::EXCEPTION event is triggered - * - * @param GetResponseForExceptionEvent $event - * @return null - */ - public function on_kernel_exception(GetResponseForExceptionEvent $event) - { - page_header($this->user->lang('INFORMATION')); - - $this->template->assign_vars(array( - 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), - 'MESSAGE_TEXT' => $event->getException()->getMessage(), - )); - - $this->template->set_filenames(array( - 'body' => 'message_body.html', - )); - - page_footer(true, false, false); - - $event->setResponse(new Response($this->template->return_display('body'), 404)); - } - - public static function getSubscribedEvents() - { - return array( - KernelEvents::TERMINATE => 'on_kernel_terminate', - KernelEvents::EXCEPTION => 'on_kernel_exception', - ); - } -} From f9f03435f0681ab1aba1ff23d84fb4101be37e46 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 17:03:06 -0400 Subject: [PATCH 08/29] [feature/compiled-dic] Move this to the other PR PHPBB3-11152 --- phpBB/download/file.php | 4 +--- phpBB/install/database_update.php | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 85dc8acb81..3e71bf9961 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -63,9 +63,7 @@ if (isset($_GET['avatar'])) new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_core($phpbb_root_path), ), - array( - new phpbb_event_kernel_compiler_pass(), - ), + array(), $phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 65c72ad635..3d296545b4 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -121,9 +121,7 @@ $phpbb_container = phpbb_create_compiled_container( new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_core($phpbb_root_path), ), - array( - new phpbb_event_kernel_compiler_pass(), - ), + array(), $phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx From ad3edf505a9e9ef7f139b033f70a1106539ce0de Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 21 Oct 2012 14:20:52 -0400 Subject: [PATCH 09/29] [feature/compiled-dic] Add HttpKernel; the Extension class is loaded from it The phpbb_di_extension_* classes extend the Extension class that is included in the HttpKernel component. If I don't include HttpKernel I have to implement the ExtensionInterface from the DependencyInjection component and have to define all of the methods; this way, I can just overwrite what I need. PHPBB3-10864 --- phpBB/composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/composer.json b/phpBB/composer.json index 5e88144bc4..380bdc367c 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -4,6 +4,7 @@ "symfony/config": "2.1.*", "symfony/dependency-injection": "2.1.*", "symfony/event-dispatcher": "2.1.*", + "symfony/http-kernel": "2.1.*", "symfony/yaml": "2.1.*" }, "require-dev": { From cb2725dd5a04118de8628e10f940e926f4fa8fa1 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 21 Oct 2012 16:09:43 -0400 Subject: [PATCH 10/29] [feature/compiled-dic] Fix cron task loading We cannot use container tags at run time if we are using a cached, compiled container object (i.e. phpbb_cache_container) so we have to load them beforehand. PHPBB3-11152 --- phpBB/common.php | 5 +- phpBB/composer.lock | 750 ++++++++++++++++++++++-- phpBB/config/services.yml | 4 + phpBB/download/file.php | 5 +- phpBB/includes/cron/task/collection.php | 72 +++ phpBB/includes/cron/task/provider.php | 27 +- phpBB/includes/di/pass/cron.php | 38 ++ phpBB/install/database_update.php | 5 +- 8 files changed, 856 insertions(+), 50 deletions(-) create mode 100644 phpBB/includes/cron/task/collection.php create mode 100644 phpBB/includes/di/pass/cron.php diff --git a/phpBB/common.php b/phpBB/common.php index fce08f3834..6a7def1884 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -104,8 +104,9 @@ $phpbb_container = phpbb_create_compiled_container( new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_core($phpbb_root_path), ), - array(), - $phpbb_root_path . 'config.' . $phpEx, + array( + new phpbb_di_pass_cron(), + ), $phpbb_root_path, $phpEx ); diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 6b0d3584d1..44c2723842 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,67 +1,749 @@ { - "hash": "1632798bc1d5298a4f5bd3087c972a9f", + "hash": "f83c386aaaf04acc7fd1724dd46c0127", "packages": [ { - "package": "symfony/config", - "version": "v2.1.0-RC1" + "name": "symfony/config", + "version": "v2.1.2", + "target-dir": "Symfony/Component/Config", + "source": { + "type": "git", + "url": "https://github.com/symfony/Config", + "reference": "v2.1.2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Config/zipball/v2.1.2", + "reference": "v2.1.2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-08-22 06:48:41", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\Config": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Config Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/dependency-injection", - "version": "v2.1.0-RC1" + "name": "symfony/dependency-injection", + "version": "v2.1.2", + "target-dir": "Symfony/Component/DependencyInjection", + "source": { + "type": "git", + "url": "https://github.com/symfony/DependencyInjection", + "reference": "v2.1.2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/DependencyInjection/zipball/v2.1.2", + "reference": "v2.1.2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/yaml": "2.1.*", + "symfony/config": "2.1.*" + }, + "suggest": { + "symfony/yaml": "2.1.*", + "symfony/config": "2.1.*" + }, + "time": "2012-09-17 13:41:57", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\DependencyInjection": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony DependencyInjection Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/event-dispatcher", - "version": "v2.1.0-RC1" + "name": "symfony/event-dispatcher", + "version": "v2.1.2", + "target-dir": "Symfony/Component/EventDispatcher", + "source": { + "type": "git", + "url": "https://github.com/symfony/EventDispatcher", + "reference": "v2.1.2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/EventDispatcher/zipball/v2.1.2", + "reference": "v2.1.2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/dependency-injection": "2.1.*" + }, + "suggest": { + "symfony/dependency-injection": "2.1.*", + "symfony/http-kernel": "2.1.*" + }, + "time": "2012-09-10 03:53:42", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\EventDispatcher": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/yaml", - "version": "v2.1.0-RC1" + "name": "symfony/http-foundation", + "version": "v2.1.2", + "target-dir": "Symfony/Component/HttpFoundation", + "source": { + "type": "git", + "url": "https://github.com/symfony/HttpFoundation", + "reference": "v2.1.2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/HttpFoundation/zipball/v2.1.2", + "reference": "v2.1.2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-09-18 09:09:52", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\HttpFoundation": "", + "SessionHandlerInterface": "Symfony/Component/HttpFoundation/Resources/stubs" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony HttpFoundation Component", + "homepage": "http://symfony.com" + }, + { + "name": "symfony/http-kernel", + "version": "v2.1.2", + "target-dir": "Symfony/Component/HttpKernel", + "source": { + "type": "git", + "url": "https://github.com/symfony/HttpKernel", + "reference": "v2.1.2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/HttpKernel/zipball/v2.1.2", + "reference": "v2.1.2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/event-dispatcher": "2.1.*", + "symfony/http-foundation": "2.1.*" + }, + "require-dev": { + "symfony/browser-kit": "2.1.*", + "symfony/class-loader": "2.1.*", + "symfony/config": "2.1.*", + "symfony/console": "2.1.*", + "symfony/dependency-injection": "2.1.*", + "symfony/finder": "2.1.*", + "symfony/process": "2.1.*", + "symfony/routing": "2.1.*" + }, + "suggest": { + "symfony/browser-kit": "2.1.*", + "symfony/class-loader": "2.1.*", + "symfony/config": "2.1.*", + "symfony/console": "2.1.*", + "symfony/dependency-injection": "2.1.*", + "symfony/finder": "2.1.*" + }, + "time": "2012-09-20 00:13:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\HttpKernel": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony HttpKernel Component", + "homepage": "http://symfony.com" + }, + { + "name": "symfony/yaml", + "version": "v2.1.2", + "target-dir": "Symfony/Component/Yaml", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml", + "reference": "v2.1.0-RC2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Yaml/zipball/v2.1.0-RC2", + "reference": "v2.1.0-RC2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-08-22 06:48:41", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\Yaml": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com" } ], "packages-dev": [ { - "package": "fabpot/goutte", + "name": "fabpot/goutte", "version": "dev-master", - "alias-pretty-version": "1.0.x-dev", - "alias-version": "1.0.9999999.9999999-dev" + "source": { + "type": "git", + "url": "https://github.com/fabpot/Goutte", + "reference": "e1c3306617e350ac17e7631166fd3fd7d689e8ea" + }, + "dist": { + "type": "zip", + "url": "https://github.com/fabpot/Goutte/zipball/e1c3306617e350ac17e7631166fd3fd7d689e8ea", + "reference": "e1c3306617e350ac17e7631166fd3fd7d689e8ea", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "symfony/browser-kit": "2.1.*", + "symfony/css-selector": "2.1.*", + "symfony/dom-crawler": "2.1.*", + "symfony/finder": "2.1.*", + "symfony/process": "2.1.*", + "ext-curl": "*", + "guzzle/http": "2.8.*" + }, + "time": "1349861753", + "type": "application", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "installation-source": "source", + "autoload": { + "psr-0": { + "Goutte": "." + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "A simple PHP Web Scraper", + "homepage": "https://github.com/fabpot/Goutte", + "keywords": [ + "scraper" + ] }, { - "package": "fabpot/goutte", - "version": "dev-master", - "source-reference": "6d26279344736f6983a969e46afef082ebf30a67", - "commit-date": "1345141401" + "name": "guzzle/common", + "version": "v2.8.8", + "target-dir": "Guzzle/Common", + "source": { + "type": "git", + "url": "git://github.com/guzzle/common.git", + "reference": "v2.8.8" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/common/zipball/v2.8.8", + "reference": "v2.8.8", + "shasum": "" + }, + "require": { + "php": ">=5.3.2", + "symfony/event-dispatcher": "2.1.*" + }, + "time": "2012-10-15 17:42:47", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "Guzzle\\Common": "" + } + }, + "license": [ + "MIT" + ], + "description": "Common libraries used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "log", + "event", + "cache", + "validation", + "Socket", + "common", + "batch", + "inflection" + ] }, { - "package": "guzzle/common", - "version": "v2.8.4" + "name": "guzzle/http", + "version": "v2.8.8", + "target-dir": "Guzzle/Http", + "source": { + "type": "git", + "url": "git://github.com/guzzle/http.git", + "reference": "v2.8.8" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/http/zipball/v2.8.8", + "reference": "v2.8.8", + "shasum": "" + }, + "require": { + "php": ">=5.3.2", + "guzzle/common": "self.version", + "guzzle/parser": "self.version" + }, + "time": "2012-10-15 17:42:47", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "Guzzle\\Http": "" + } + }, + "license": [ + "MIT" + ], + "description": "HTTP libraries used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "curl", + "http", + "http client", + "client", + "Guzzle" + ] }, { - "package": "guzzle/http", - "version": "v2.8.4" + "name": "guzzle/parser", + "version": "v2.8.8", + "target-dir": "Guzzle/Parser", + "source": { + "type": "git", + "url": "git://github.com/guzzle/parser.git", + "reference": "v2.8.8" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/parser/zipball/v2.8.8", + "reference": "v2.8.8", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "time": "2012-09-20 13:28:06", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "Guzzle\\Parser": "" + } + }, + "license": [ + "MIT" + ], + "description": "Interchangeable parsers used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "http", + "url", + "message", + "cookie", + "URI Template" + ] }, { - "package": "guzzle/parser", - "version": "v2.8.4" + "name": "symfony/browser-kit", + "version": "v2.1.2", + "target-dir": "Symfony/Component/BrowserKit", + "source": { + "type": "git", + "url": "https://github.com/symfony/BrowserKit", + "reference": "v2.1.2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/BrowserKit/zipball/v2.1.2", + "reference": "v2.1.2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/dom-crawler": "2.1.*" + }, + "require-dev": { + "symfony/process": "2.1.*", + "symfony/css-selector": "2.1.*" + }, + "suggest": { + "symfony/process": "2.1.*" + }, + "time": "2012-09-10 03:53:42", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\BrowserKit": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony BrowserKit Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/browser-kit", - "version": "v2.1.0-RC1" + "name": "symfony/css-selector", + "version": "v2.1.2", + "target-dir": "Symfony/Component/CssSelector", + "source": { + "type": "git", + "url": "https://github.com/symfony/CssSelector", + "reference": "v2.1.0-RC2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/CssSelector/zipball/v2.1.0-RC2", + "reference": "v2.1.0-RC2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-08-22 06:48:41", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\CssSelector": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony CssSelector Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/css-selector", - "version": "v2.1.0-RC1" + "name": "symfony/dom-crawler", + "version": "v2.1.2", + "target-dir": "Symfony/Component/DomCrawler", + "source": { + "type": "git", + "url": "https://github.com/symfony/DomCrawler", + "reference": "v2.1.2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/DomCrawler/zipball/v2.1.2", + "reference": "v2.1.2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/css-selector": "2.1.*" + }, + "suggest": { + "symfony/css-selector": "2.1.*" + }, + "time": "2012-09-10 03:53:42", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\DomCrawler": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony DomCrawler Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/dom-crawler", - "version": "v2.1.0-RC1" + "name": "symfony/finder", + "version": "v2.1.2", + "target-dir": "Symfony/Component/Finder", + "source": { + "type": "git", + "url": "https://github.com/symfony/Finder", + "reference": "v2.1.2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Finder/zipball/v2.1.2", + "reference": "v2.1.2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-08-22 06:48:41", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\Finder": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/finder", - "version": "v2.1.0-RC1" - }, - { - "package": "symfony/process", - "version": "v2.1.0-RC1" + "name": "symfony/process", + "version": "v2.1.2", + "target-dir": "Symfony/Component/Process", + "source": { + "type": "git", + "url": "https://github.com/symfony/Process", + "reference": "v2.1.2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Process/zipball/v2.1.2", + "reference": "v2.1.2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-09-18 15:37:29", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\Process": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "http://symfony.com" } ], "aliases": [ diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 6c904ac2c8..b77c3d6c3f 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -47,8 +47,12 @@ services: cron.task_provider: class: phpbb_cron_task_provider arguments: + - @cron.task_collection - @service_container + cron.task_collection: + class: phpbb_cron_task_collection + cron.manager: class: phpbb_cron_manager arguments: diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 3e71bf9961..7ffd335daa 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -63,8 +63,9 @@ if (isset($_GET['avatar'])) new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_core($phpbb_root_path), ), - array(), - $phpbb_root_path . 'config.' . $phpEx, + array( + new phpbb_di_pass_cron(), + ), $phpbb_root_path, $phpEx ); diff --git a/phpBB/includes/cron/task/collection.php b/phpBB/includes/cron/task/collection.php new file mode 100644 index 0000000000..d05be9012c --- /dev/null +++ b/phpBB/includes/cron/task/collection.php @@ -0,0 +1,72 @@ +tasks[$offset]); + } + + /** + * ArrayAccess method + * + * @param mixed $offset Array offset + */ + public function offsetGet($offset) + { + return $this->offsetExists($offset) ? $this->tasks[$offset] : null; + } + + /** + * ArrayAccess method + * + * @param mixed $offset Array offset + * @param mixed $value New value + */ + public function offsetSet($offset, $value) + { + if ($offset === null) + { + $this->tasks[] = $value; + } + else + { + $this->tasks[$offset] = $value; + } + } + + /** + * ArrayAccess method + * + * @param mixed $offset Array offset + */ + public function offsetUnset($offset) + { + $this->tasks[$offset] = null; + } +} diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index 134723ebd1..08e54a651a 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -26,10 +26,11 @@ use Symfony\Component\DependencyInjection\TaggedContainerInterface; */ class phpbb_cron_task_provider implements IteratorAggregate { - private $container; + private $tasks; - public function __construct(TaggedContainerInterface $container) + public function __construct(phpbb_cron_task_collection $tasks, TaggedContainerInterface $container) { + $this->tasks = $tasks; $this->container = $container; } @@ -40,18 +41,24 @@ class phpbb_cron_task_provider implements IteratorAggregate */ public function getIterator() { - $definitions = $this->container->findTaggedServiceIds('cron.task'); - $tasks = array(); - foreach ($definitions as $name => $definition) + foreach ($this->tasks as $names) { - $task = $this->container->get($name); - if ($task instanceof phpbb_cron_task_base) + foreach ($names as $name) { - $task->set_name($name); - } + if (!$this->container->has($name)) + { + continue; + } - $tasks[] = $task; + $task = $this->container->get($name); + if ($task instanceof phpbb_cron_task_base) + { + $task->set_name($name); + } + + $tasks[] = $task; + } } return new ArrayIterator($tasks); diff --git a/phpBB/includes/di/pass/cron.php b/phpBB/includes/di/pass/cron.php new file mode 100644 index 0000000000..b5fc4af9fc --- /dev/null +++ b/phpBB/includes/di/pass/cron.php @@ -0,0 +1,38 @@ +getDefinition('cron.task_collection'); + + foreach ($container->findTaggedServiceIds('cron.task') as $id => $data) + { + $definition->addMethodCall('offsetSet', array(null, $id)); + } + } +} diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 3d296545b4..1734272486 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -121,8 +121,9 @@ $phpbb_container = phpbb_create_compiled_container( new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_core($phpbb_root_path), ), - array(), - $phpbb_root_path . 'config.' . $phpEx, + array( + new phpbb_di_pass_cron(), + ), $phpbb_root_path, $phpEx ); From a6428c8dc3c211675da5e7e58503849791d2d3e5 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 22 Oct 2012 11:17:49 -0400 Subject: [PATCH 11/29] [feature/compiled-dic] Fix cron tasks again PHPBB3-11152 --- phpBB/config/services.yml | 10 ++-- phpBB/includes/cron/task/collection.php | 51 ++++++------------- phpBB/includes/cron/task/provider.php | 66 ------------------------- phpBB/includes/di/pass/cron.php | 2 +- 4 files changed, 18 insertions(+), 111 deletions(-) delete mode 100644 phpBB/includes/cron/task/provider.php diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index b77c3d6c3f..b1aaf1660d 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -44,19 +44,15 @@ services: - @cache.driver - %tables.config% - cron.task_provider: - class: phpbb_cron_task_provider - arguments: - - @cron.task_collection - - @service_container - cron.task_collection: class: phpbb_cron_task_collection + arguments: + - @service_container cron.manager: class: phpbb_cron_manager arguments: - - @cron.task_provider + - @cron.task_collection - %core.root_path% - %core.php_ext% diff --git a/phpBB/includes/cron/task/collection.php b/phpBB/includes/cron/task/collection.php index d05be9012c..84607dc28d 100644 --- a/phpBB/includes/cron/task/collection.php +++ b/phpBB/includes/cron/task/collection.php @@ -15,58 +15,35 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\TaggedContainerInterface; + /** * Collects cron tasks * * @package phpBB3 */ -class phpbb_cron_task_collection implements ArrayAccess +class phpbb_cron_task_collection extends ArrayObject { /** - * ArrayAccess method + * Constructor * - * @param mixed $offset Array offset + * @param TaggedContainerInterface $container Container object */ - public function offsetExists($offset) + public function __construct(TaggedContainerInterface $container) { - return isset($this->tasks[$offset]); + $this->container = $container; } /** - * ArrayAccess method + * Add a cron task to the collection * - * @param mixed $offset Array offset + * @param string $name The service name of the cron task + * @return null */ - public function offsetGet($offset) + public function add($name) { - return $this->offsetExists($offset) ? $this->tasks[$offset] : null; - } - - /** - * ArrayAccess method - * - * @param mixed $offset Array offset - * @param mixed $value New value - */ - public function offsetSet($offset, $value) - { - if ($offset === null) - { - $this->tasks[] = $value; - } - else - { - $this->tasks[$offset] = $value; - } - } - - /** - * ArrayAccess method - * - * @param mixed $offset Array offset - */ - public function offsetUnset($offset) - { - $this->tasks[$offset] = null; + $task = $this->container->get($name); + $task->set_name($name); + $this->offsetSet($name, $task); } } diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php deleted file mode 100644 index 08e54a651a..0000000000 --- a/phpBB/includes/cron/task/provider.php +++ /dev/null @@ -1,66 +0,0 @@ -tasks = $tasks; - $this->container = $container; - } - - /** - * Retrieve an iterator over all items - * - * @return ArrayIterator An iterator for the array of cron tasks - */ - public function getIterator() - { - $tasks = array(); - foreach ($this->tasks as $names) - { - foreach ($names as $name) - { - if (!$this->container->has($name)) - { - continue; - } - - $task = $this->container->get($name); - if ($task instanceof phpbb_cron_task_base) - { - $task->set_name($name); - } - - $tasks[] = $task; - } - } - - return new ArrayIterator($tasks); - } -} diff --git a/phpBB/includes/di/pass/cron.php b/phpBB/includes/di/pass/cron.php index b5fc4af9fc..53fe0a61c8 100644 --- a/phpBB/includes/di/pass/cron.php +++ b/phpBB/includes/di/pass/cron.php @@ -32,7 +32,7 @@ class phpbb_di_pass_cron implements CompilerPassInterface foreach ($container->findTaggedServiceIds('cron.task') as $id => $data) { - $definition->addMethodCall('offsetSet', array(null, $id)); + $definition->addMethodCall('add', array($id)); } } } From 1e3a5dde7d232054d86f91f6908cc23f8b726fdf Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 22 Oct 2012 11:27:07 -0400 Subject: [PATCH 12/29] [feature/compiled-dic] Remove old test PHPBB3-11152 --- tests/cron/task_provider_test.php | 50 ------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 tests/cron/task_provider_test.php diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php deleted file mode 100644 index ec853bb3ba..0000000000 --- a/tests/cron/task_provider_test.php +++ /dev/null @@ -1,50 +0,0 @@ -tasks = array( - 'phpbb_cron_task_core_dummy_task', - 'phpbb_cron_task_core_second_dummy_task', - 'phpbb_ext_testext_cron_dummy_task', - ); - - $container = $this->getMock('Symfony\Component\DependencyInjection\TaggedContainerInterface'); - $container - ->expects($this->once()) - ->method('findTaggedServiceIds') - ->will($this->returnValue(array_flip($this->tasks))); - $container - ->expects($this->any()) - ->method('get') - ->will($this->returnCallback(function ($name) { - return new $name; - })); - - $this->provider = new phpbb_cron_task_provider($container); - } - - public function test_manager_finds_shipped_tasks() - { - $task_names = array(); - foreach ($this->provider as $task) - { - $task_names[] = $task->get_name(); - } - sort($task_names); - - $this->assertEquals(array( - 'phpbb_cron_task_core_dummy_task', - 'phpbb_cron_task_core_second_dummy_task', - 'phpbb_ext_testext_cron_dummy_task', - ), $task_names); - } -} From af3f07d8c9d79b305f34eb19aa100786d4a3faf8 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 22 Oct 2012 12:17:06 -0400 Subject: [PATCH 13/29] [feature/compiled-dic] Fix root path when container is created after install PHPBB3-11152 --- phpBB/includes/functions.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index ac63bd086c..bb98ba4eb9 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5484,6 +5484,23 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb return new phpbb_cache_container(); } + // When the board is first installed, the container is initiall created on + // the send_statistics step in the ACP. In that case, the phpbb_root_path + // is "./../". This becomes forever stored in the cached container as the + // core.root_path property, until the container is deleted and recached + // We need to ensure that this does not happen. + // + // However, if we change the root path here, it will try to create a + // ./adm/cache/container.php later on because the root path is wrong + // We need to store the current $phpbb_root_path for use later and then we + // can change it for the controller + $real_root_path = $phpbb_root_path; + if (defined('ADMIN_START')) + { + // Remove the first instance of ../ in the root path + $phpbb_root_path = preg_replace('/..\//', '', $phpbb_root_path, 1); + } + // If we don't have the cached container class, we make it now // First, we create the temporary container so we can access the // extension_manager @@ -5509,7 +5526,8 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', )); - $file = file_put_contents("{$phpbb_root_path}cache/container.$phpEx", $cached_container_dump); + // Use the $real_root_path in case $phpbb_root_path was changed above + $file = file_put_contents("{$real_root_path}cache/container.$phpEx", $cached_container_dump); return $container; } From c16bb2b2c62f3fa68716b40745cba437cebe5433 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 2 Nov 2012 16:40:12 -0400 Subject: [PATCH 14/29] [feature/compiled-dic] Purge cache to make ext services available right away PHPBB3-11152 --- phpBB/includes/extension/manager.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index cfa6a0e000..bfd4edde93 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -195,7 +195,7 @@ class phpbb_extension_manager if ($this->cache) { - $this->cache->destroy($this->cache_name); + $this->cache->purge(); } return !$active; @@ -252,7 +252,7 @@ class phpbb_extension_manager if ($this->cache) { - $this->cache->destroy($this->cache_name); + $this->cache->purge(); } return true; @@ -272,7 +272,7 @@ class phpbb_extension_manager if ($this->cache) { - $this->cache->destroy($this->cache_name); + $this->cache->purge(); } return false; @@ -335,7 +335,7 @@ class phpbb_extension_manager if ($this->cache) { - $this->cache->destroy($this->cache_name); + $this->cache->purge(); } return true; @@ -349,7 +349,7 @@ class phpbb_extension_manager if ($this->cache) { - $this->cache->destroy($this->cache_name); + $this->cache->purge(); } return false; From e6a6e85d7e6ce53eb7167ea82f08e06c55a87b00 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 2 Nov 2012 16:41:51 -0400 Subject: [PATCH 15/29] [feature/compiled-dic] Update the composer.lock file PHPBB3-11152 --- phpBB/composer.lock | 120 ++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 44c2723842..69e4a2b4b8 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,25 +1,25 @@ { - "hash": "f83c386aaaf04acc7fd1724dd46c0127", + "hash": "407cc89f4bb0e409146c863dee51b0ae", "packages": [ { "name": "symfony/config", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/Config", "source": { "type": "git", "url": "https://github.com/symfony/Config", - "reference": "v2.1.2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/Config/zipball/v2.1.2", - "reference": "v2.1.2", + "url": "https://github.com/symfony/Config/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { "php": ">=5.3.3" }, - "time": "2012-08-22 06:48:41", + "time": "2012-10-20 00:10:30", "type": "library", "extra": { "branch-alias": { @@ -50,17 +50,17 @@ }, { "name": "symfony/dependency-injection", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/DependencyInjection", "source": { "type": "git", "url": "https://github.com/symfony/DependencyInjection", - "reference": "v2.1.2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/DependencyInjection/zipball/v2.1.2", - "reference": "v2.1.2", + "url": "https://github.com/symfony/DependencyInjection/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { @@ -74,7 +74,7 @@ "symfony/yaml": "2.1.*", "symfony/config": "2.1.*" }, - "time": "2012-09-17 13:41:57", + "time": "2012-10-22 07:37:12", "type": "library", "extra": { "branch-alias": { @@ -105,17 +105,17 @@ }, { "name": "symfony/event-dispatcher", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/EventDispatcher", "source": { "type": "git", "url": "https://github.com/symfony/EventDispatcher", - "reference": "v2.1.2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/EventDispatcher/zipball/v2.1.2", - "reference": "v2.1.2", + "url": "https://github.com/symfony/EventDispatcher/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { @@ -128,7 +128,7 @@ "symfony/dependency-injection": "2.1.*", "symfony/http-kernel": "2.1.*" }, - "time": "2012-09-10 03:53:42", + "time": "2012-10-04 08:17:57", "type": "library", "extra": { "branch-alias": { @@ -159,23 +159,23 @@ }, { "name": "symfony/http-foundation", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/HttpFoundation", "source": { "type": "git", "url": "https://github.com/symfony/HttpFoundation", - "reference": "v2.1.2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/HttpFoundation/zipball/v2.1.2", - "reference": "v2.1.2", + "url": "https://github.com/symfony/HttpFoundation/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { "php": ">=5.3.3" }, - "time": "2012-09-18 09:09:52", + "time": "2012-10-20 00:10:30", "type": "library", "extra": { "branch-alias": { @@ -207,17 +207,17 @@ }, { "name": "symfony/http-kernel", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/HttpKernel", "source": { "type": "git", "url": "https://github.com/symfony/HttpKernel", - "reference": "v2.1.2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/HttpKernel/zipball/v2.1.2", - "reference": "v2.1.2", + "url": "https://github.com/symfony/HttpKernel/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { @@ -243,7 +243,7 @@ "symfony/dependency-injection": "2.1.*", "symfony/finder": "2.1.*" }, - "time": "2012-09-20 00:13:00", + "time": "2012-10-30 01:14:14", "type": "library", "extra": { "branch-alias": { @@ -274,23 +274,23 @@ }, { "name": "symfony/yaml", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/Yaml", "source": { "type": "git", "url": "https://github.com/symfony/Yaml", - "reference": "v2.1.0-RC2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/Yaml/zipball/v2.1.0-RC2", - "reference": "v2.1.0-RC2", + "url": "https://github.com/symfony/Yaml/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { "php": ">=5.3.3" }, - "time": "2012-08-22 06:48:41", + "time": "2012-10-29 04:15:41", "type": "library", "extra": { "branch-alias": { @@ -327,12 +327,12 @@ "source": { "type": "git", "url": "https://github.com/fabpot/Goutte", - "reference": "e1c3306617e350ac17e7631166fd3fd7d689e8ea" + "reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48" }, "dist": { "type": "zip", - "url": "https://github.com/fabpot/Goutte/zipball/e1c3306617e350ac17e7631166fd3fd7d689e8ea", - "reference": "e1c3306617e350ac17e7631166fd3fd7d689e8ea", + "url": "https://github.com/fabpot/Goutte/zipball/f2940f9c7c1f409159f5e9f512e575946c5cff48", + "reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48", "shasum": "" }, "require": { @@ -345,7 +345,7 @@ "ext-curl": "*", "guzzle/http": "2.8.*" }, - "time": "1349861753", + "time": "1351086217", "type": "application", "extra": { "branch-alias": { @@ -498,17 +498,17 @@ }, { "name": "symfony/browser-kit", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/BrowserKit", "source": { "type": "git", "url": "https://github.com/symfony/BrowserKit", - "reference": "v2.1.2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/BrowserKit/zipball/v2.1.2", - "reference": "v2.1.2", + "url": "https://github.com/symfony/BrowserKit/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { @@ -522,7 +522,7 @@ "suggest": { "symfony/process": "2.1.*" }, - "time": "2012-09-10 03:53:42", + "time": "2012-10-25 06:11:50", "type": "library", "extra": { "branch-alias": { @@ -553,23 +553,23 @@ }, { "name": "symfony/css-selector", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/CssSelector", "source": { "type": "git", "url": "https://github.com/symfony/CssSelector", - "reference": "v2.1.0-RC2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/CssSelector/zipball/v2.1.0-RC2", - "reference": "v2.1.0-RC2", + "url": "https://github.com/symfony/CssSelector/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { "php": ">=5.3.3" }, - "time": "2012-08-22 06:48:41", + "time": "2012-10-04 08:17:57", "type": "library", "extra": { "branch-alias": { @@ -600,17 +600,17 @@ }, { "name": "symfony/dom-crawler", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/DomCrawler", "source": { "type": "git", "url": "https://github.com/symfony/DomCrawler", - "reference": "v2.1.2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/DomCrawler/zipball/v2.1.2", - "reference": "v2.1.2", + "url": "https://github.com/symfony/DomCrawler/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { @@ -622,7 +622,7 @@ "suggest": { "symfony/css-selector": "2.1.*" }, - "time": "2012-09-10 03:53:42", + "time": "2012-10-18 14:16:01", "type": "library", "extra": { "branch-alias": { @@ -653,23 +653,23 @@ }, { "name": "symfony/finder", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/Finder", "source": { "type": "git", "url": "https://github.com/symfony/Finder", - "reference": "v2.1.2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/Finder/zipball/v2.1.2", - "reference": "v2.1.2", + "url": "https://github.com/symfony/Finder/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { "php": ">=5.3.3" }, - "time": "2012-08-22 06:48:41", + "time": "2012-10-20 00:10:30", "type": "library", "extra": { "branch-alias": { @@ -700,23 +700,23 @@ }, { "name": "symfony/process", - "version": "v2.1.2", + "version": "v2.1.3", "target-dir": "Symfony/Component/Process", "source": { "type": "git", "url": "https://github.com/symfony/Process", - "reference": "v2.1.2" + "reference": "v2.1.3" }, "dist": { "type": "zip", - "url": "https://github.com/symfony/Process/zipball/v2.1.2", - "reference": "v2.1.2", + "url": "https://github.com/symfony/Process/zipball/v2.1.3", + "reference": "v2.1.3", "shasum": "" }, "require": { "php": ">=5.3.3" }, - "time": "2012-09-18 15:37:29", + "time": "2012-10-20 00:10:30", "type": "library", "extra": { "branch-alias": { From 2de8827b1e35d7e522303cadf37da4878bdc89a3 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 2 Nov 2012 16:42:35 -0400 Subject: [PATCH 16/29] [feature/compiled-dic] Use an absolute path for core.root_path parameter PHPBB3-11152 --- phpBB/includes/functions.php | 40 +++++++++++++++++------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index bb98ba4eb9..b7905c5510 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5484,35 +5484,34 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb return new phpbb_cache_container(); } - // When the board is first installed, the container is initiall created on - // the send_statistics step in the ACP. In that case, the phpbb_root_path - // is "./../". This becomes forever stored in the cached container as the - // core.root_path property, until the container is deleted and recached - // We need to ensure that this does not happen. - // - // However, if we change the root path here, it will try to create a - // ./adm/cache/container.php later on because the root path is wrong - // We need to store the current $phpbb_root_path for use later and then we - // can change it for the controller - $real_root_path = $phpbb_root_path; + // When the board is first installed, the container is initially created + // during the send_statistics step in the ACP. At that point, the path + // relative to the board root is "./../". This becomes forever stored in + // the cached container as the core.root_path property, until the + // container is deleted and recached. We need to ensure that this does + // not happen. if (defined('ADMIN_START')) { // Remove the first instance of ../ in the root path - $phpbb_root_path = preg_replace('/..\//', '', $phpbb_root_path, 1); + $phpbb_root_path = preg_replace('/\.\.\//', '', $phpbb_root_path, 1); } - // If we don't have the cached container class, we make it now - // First, we create the temporary container so we can access the - // extension_manager - $tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $phpEx); + // 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, $phpEx); $tmp_container->compile(); - // Now we pass the enabled extension paths into the ext compiler extension + // Now pass the enabled extension paths into the ext compiler extension $extensions[] = new phpbb_di_extension_ext($tmp_container->get('ext.manager')->all_enabled()); - // And create our final container - $container = phpbb_create_container($extensions, $phpbb_root_path, $phpEx); + // Create the final container to be compiled and cached + $container = phpbb_create_container($extensions, $phpbb_absolute_path, $phpEx); + // Compile the container foreach ($passes as $pass) { $container->addCompilerPass($pass); @@ -5526,8 +5525,7 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', )); - // Use the $real_root_path in case $phpbb_root_path was changed above - $file = file_put_contents("{$real_root_path}cache/container.$phpEx", $cached_container_dump); + $file = file_put_contents("{$phpbb_absolute_path}cache/container.{$phpEx}", $cached_container_dump); return $container; } From 3f2cbaac34e1cf126c73bebc7dcc3cdbd203d1b2 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 2 Nov 2012 18:36:52 -0400 Subject: [PATCH 17/29] [feature/compiled-dic] Rename $phpEx to $php_ext in new code PHPBB3-11152 --- phpBB/includes/functions.php | 40 +++++++++++++----------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b7905c5510..b4db1ff891 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5425,10 +5425,10 @@ function phpbb_to_numeric($input) * * @param array $extensions Array of Container extension objects * @param string $phpbb_root_path Root path -* @param string $phpEx PHP Extension +* @param string $php_ext PHP Extension * @return ContainerBuilder object */ -function phpbb_create_container(array $extensions, $phpbb_root_path, $phpEx) +function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext) { $container = new ContainerBuilder(); @@ -5439,7 +5439,7 @@ function phpbb_create_container(array $extensions, $phpbb_root_path, $phpEx) } $container->setParameter('core.root_path', $phpbb_root_path); - $container->setParameter('core.php_ext', $phpEx); + $container->setParameter('core.php_ext', $php_ext); return $container; } @@ -5448,10 +5448,10 @@ function phpbb_create_container(array $extensions, $phpbb_root_path, $phpEx) * Create installer container * * @param string $phpbb_root_path Root path -* @param string $phpEx PHP Extension +* @param string $php_ext PHP Extension * @return ContainerBuilder object */ -function phpbb_create_install_container($phpbb_root_path, $phpEx) +function phpbb_create_install_container($phpbb_root_path, $php_ext) { // We have to do it like this instead of with extensions $container = new ContainerBuilder(); @@ -5459,7 +5459,7 @@ function phpbb_create_install_container($phpbb_root_path, $phpEx) $loader->load('services.yml'); $container->setParameter('core.root_path', $phpbb_root_path); - $container->setParameter('core.php_ext', $phpEx); + $container->setParameter('core.php_ext', $php_ext); $container->setAlias('cache.driver', 'cache.driver.install'); @@ -5472,44 +5472,32 @@ function phpbb_create_install_container($phpbb_root_path, $phpEx) * @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 $phpEx PHP Extension +* @param string $php_ext PHP Extension * @return ContainerBuilder object (compiled) */ -function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $phpEx) +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.$phpEx")) + if (file_exists("{$phpbb_root_path}cache/container.$php_ext")) { - require("{$phpbb_root_path}cache/container.$phpEx"); + require("{$phpbb_root_path}cache/container.$php_ext"); return new phpbb_cache_container(); } - // When the board is first installed, the container is initially created - // during the send_statistics step in the ACP. At that point, the path - // relative to the board root is "./../". This becomes forever stored in - // the cached container as the core.root_path property, until the - // container is deleted and recached. We need to ensure that this does - // not happen. - if (defined('ADMIN_START')) - { - // Remove the first instance of ../ in the root path - $phpbb_root_path = preg_replace('/\.\.\//', '', $phpbb_root_path, 1); - } - // 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); + $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, $phpEx); + $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, $phpEx); + $container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext); // Compile the container foreach ($passes as $pass) @@ -5525,7 +5513,7 @@ 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.{$phpEx}", $cached_container_dump); + $file = file_put_contents("{$phpbb_absolute_path}cache/container.{$php_ext}", $cached_container_dump); return $container; } From 897e8f2e8361839a92acae7e77225ef212e44647 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 9 Nov 2012 23:00:44 +0100 Subject: [PATCH 18/29] [ticket/11152] Move container functions to a separate function file PHPBB3-11152 --- phpBB/common.php | 1 + phpBB/download/file.php | 3 +- phpBB/includes/functions.php | 105 ---------------------- phpBB/includes/functions_container.php | 119 +++++++++++++++++++++++++ phpBB/install/database_update.php | 7 +- phpBB/install/index.php | 1 + 6 files changed, 127 insertions(+), 109 deletions(-) create mode 100644 phpBB/includes/functions_container.php diff --git a/phpBB/common.php b/phpBB/common.php index 6a7def1884..e24f9b4359 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -84,6 +84,7 @@ require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); +require($phpbb_root_path . 'includes/functions_container.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/db/' . ltrim($dbms, 'dbal_') . '.' . $phpEx); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 7ffd335daa..eb1ec85afe 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -48,6 +48,7 @@ if (isset($_GET['avatar'])) require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); + require($phpbb_root_path . 'includes/functions_container.' . $phpEx); require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); @@ -404,7 +405,7 @@ else $disallowed[$attach['extension']] = $attach['extension']; continue; } - + $prefix = ''; if ($topic_id) { diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b4db1ff891..43b81f3f26 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -7,13 +7,6 @@ * */ -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\Dumper\PhpDumper; -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; - /** * @ignore */ @@ -5419,101 +5412,3 @@ function phpbb_to_numeric($input) { return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; } - -/** -* Create the ContainerBuilder object -* -* @param array $extensions Array of Container extension objects -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object -*/ -function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext) -{ - $container = new ContainerBuilder(); - - foreach ($extensions as $extension) - { - $container->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; -} 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; +} diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 1734272486..a5c4e2acd3 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -88,6 +88,7 @@ if (!empty($load_extensions) && function_exists('dl')) require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); +require($phpbb_root_path . 'includes/functions_container.' . $phpEx); phpbb_require_updated('includes/functions_content.' . $phpEx, true); @@ -2723,10 +2724,10 @@ function change_database_data(&$no_updates, $version) // Create config value for displaying last subject on forum list if (!isset($config['display_last_subject'])) - { + { $config->set('display_last_subject', '1'); } - + $no_updates = false; if (!isset($config['assets_version'])) @@ -2759,7 +2760,7 @@ function change_database_data(&$no_updates, $version) // After we have calculated the timezones we can delete user_dst column from user table. $db_tools->sql_column_remove(USERS_TABLE, 'user_dst'); } - + if (!isset($config['site_home_url'])) { $config->set('site_home_url', ''); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 0afa24066a..7975ac2709 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -77,6 +77,7 @@ else require($phpbb_root_path . 'includes/class_loader.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); +require($phpbb_root_path . 'includes/functions_container.' . $phpEx); phpbb_require_updated('includes/functions_content.' . $phpEx, true); From 38e1c4ec5d363900285a6a72ee78f4f2e2943bd0 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 09:55:17 +0100 Subject: [PATCH 19/29] [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(-) 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; +} From 798c006e7fe55bc1de30e42a4c25e8c74911c865 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 16:38:19 +0100 Subject: [PATCH 20/29] [ticket/11152] Convert cron_task_collection to generic di_service_collection PHPBB3-11152 --- phpBB/config/services.yml | 2 +- .../collection.php => di/service_collection.php} | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) rename phpBB/includes/{cron/task/collection.php => di/service_collection.php} (55%) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index b1aaf1660d..76a7049f19 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -45,7 +45,7 @@ services: - %tables.config% cron.task_collection: - class: phpbb_cron_task_collection + class: phpbb_di_service_collection arguments: - @service_container diff --git a/phpBB/includes/cron/task/collection.php b/phpBB/includes/di/service_collection.php similarity index 55% rename from phpBB/includes/cron/task/collection.php rename to phpBB/includes/di/service_collection.php index 84607dc28d..60323c8dba 100644 --- a/phpBB/includes/cron/task/collection.php +++ b/phpBB/includes/di/service_collection.php @@ -15,29 +15,29 @@ if (!defined('IN_PHPBB')) exit; } -use Symfony\Component\DependencyInjection\TaggedContainerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** -* Collects cron tasks +* Collection of services to be configured at container compile time. * * @package phpBB3 */ -class phpbb_cron_task_collection extends ArrayObject +class phpbb_di_service_collection extends ArrayObject { /** * Constructor * - * @param TaggedContainerInterface $container Container object + * @param ContainerInterface $container Container object */ - public function __construct(TaggedContainerInterface $container) + public function __construct(ContainerInterface $container) { $this->container = $container; } /** - * Add a cron task to the collection + * Add a service to the collection * - * @param string $name The service name of the cron task + * @param string $name The service name * @return null */ public function add($name) From 231d743ba9966e8304e0dd226ebf5eb7fb3b70d8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 23:34:27 +0100 Subject: [PATCH 21/29] [ticket/11152] Change phpbb_di_pass_cron to generic phpbb_di_pass_collection PHPBB3-11152 --- phpBB/common.php | 2 +- phpBB/config/services.yml | 7 ------- phpBB/download/file.php | 2 +- .../includes/di/pass/{cron.php => collection.php} | 15 ++++++++++++--- phpBB/install/database_update.php | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) rename phpBB/includes/di/pass/{cron.php => collection.php} (59%) diff --git a/phpBB/common.php b/phpBB/common.php index e24f9b4359..fb2f86341b 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -106,7 +106,7 @@ $phpbb_container = phpbb_create_compiled_container( new phpbb_di_extension_core($phpbb_root_path), ), array( - new phpbb_di_pass_cron(), + new phpbb_di_pass_collection('cron.task_collection', 'cron.task'), ), $phpbb_root_path, $phpEx diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 76a7049f19..42bb473e66 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -91,13 +91,6 @@ services: - .%core.php_ext% - @cache.driver - processor.ext: - class: phpbb_di_processor_ext - arguments: - - @ext.manager - tags: - - { name: container.processor } - request: class: phpbb_request diff --git a/phpBB/download/file.php b/phpBB/download/file.php index eb1ec85afe..b99ce2d688 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -65,7 +65,7 @@ if (isset($_GET['avatar'])) new phpbb_di_extension_core($phpbb_root_path), ), array( - new phpbb_di_pass_cron(), + new phpbb_di_pass_collection('cron.task_collection', 'cron.task'), ), $phpbb_root_path, $phpEx diff --git a/phpBB/includes/di/pass/cron.php b/phpBB/includes/di/pass/collection.php similarity index 59% rename from phpBB/includes/di/pass/cron.php rename to phpBB/includes/di/pass/collection.php index 53fe0a61c8..09e4b08f62 100644 --- a/phpBB/includes/di/pass/cron.php +++ b/phpBB/includes/di/pass/collection.php @@ -18,8 +18,17 @@ if (!defined('IN_PHPBB')) use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -class phpbb_di_pass_cron implements CompilerPassInterface +class phpbb_di_pass_collection implements CompilerPassInterface { + private $collection_service; + private $service_tag; + + public function __construct($collection_service, $service_tag) + { + $this->collection_service = $collection_service; + $this->service_tag = $service_tag; + } + /** * Modify the container before it is passed to the rest of the code * @@ -28,9 +37,9 @@ class phpbb_di_pass_cron implements CompilerPassInterface */ public function process(ContainerBuilder $container) { - $definition = $container->getDefinition('cron.task_collection'); + $definition = $container->getDefinition($this->collection_service); - foreach ($container->findTaggedServiceIds('cron.task') as $id => $data) + foreach ($container->findTaggedServiceIds($this->service_tag) as $id => $data) { $definition->addMethodCall('add', array($id)); } diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index a5c4e2acd3..bc45b27cdc 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -123,7 +123,7 @@ $phpbb_container = phpbb_create_compiled_container( new phpbb_di_extension_core($phpbb_root_path), ), array( - new phpbb_di_pass_cron(), + new phpbb_di_pass_collection('cron.task_collection', 'cron.task'), ), $phpbb_root_path, $phpEx From 8851b797fbf0f1b4120aa4d3ae713711e01ef98f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 23:35:52 +0100 Subject: [PATCH 22/29] [ticket/11152] Create separate function for debug-dependent container PHPBB3-11152 --- phpBB/common.php | 2 +- phpBB/download/file.php | 2 +- phpBB/includes/functions_container.php | 32 +++++++++++++++++++------- phpBB/install/database_update.php | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index fb2f86341b..b435970692 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -100,7 +100,7 @@ $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_pat $phpbb_class_loader_ext->register(); // Set up container -$phpbb_container = phpbb_create_compiled_container( +$phpbb_container = phpbb_create_dumped_container_unless_debug( array( new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_core($phpbb_root_path), diff --git a/phpBB/download/file.php b/phpBB/download/file.php index b99ce2d688..5ef64e6ecc 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -59,7 +59,7 @@ if (isset($_GET['avatar'])) $phpbb_class_loader_ext->register(); // Set up container - $phpbb_container = phpbb_create_compiled_container( + $phpbb_container = phpbb_create_dumped_container_unless_debug( array( new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_core($phpbb_root_path), 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); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index bc45b27cdc..add59b3c85 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -117,7 +117,7 @@ $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', "{$phpbb_root_pat $phpbb_class_loader_ext->register(); // Set up container -$phpbb_container = phpbb_create_compiled_container( +$phpbb_container = phpbb_create_dumped_container_unless_debug( array( new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx), new phpbb_di_extension_core($phpbb_root_path), From bdbf7d5de61c902c54fa5882440a5334ac7ad24f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 23:36:13 +0100 Subject: [PATCH 23/29] [ticket/11152] Remove @api docblocks PHPBB3-11152 --- phpBB/includes/di/extension/config.php | 4 ---- phpBB/includes/di/extension/core.php | 4 ---- phpBB/includes/di/extension/ext.php | 4 ---- 3 files changed, 12 deletions(-) diff --git a/phpBB/includes/di/extension/config.php b/phpBB/includes/di/extension/config.php index b9c752c5de..fb5ca90070 100644 --- a/phpBB/includes/di/extension/config.php +++ b/phpBB/includes/di/extension/config.php @@ -37,8 +37,6 @@ class phpbb_di_extension_config extends Extension * @param ContainerBuilder $container A ContainerBuilder instance * * @throws InvalidArgumentException When provided tag is not defined in this extension - * - * @api */ public function load(array $config, ContainerBuilder $container) { @@ -61,8 +59,6 @@ class phpbb_di_extension_config extends Extension * This alias is also the mandatory prefix to use when using YAML. * * @return string The alias - * - * @api */ public function getAlias() { diff --git a/phpBB/includes/di/extension/core.php b/phpBB/includes/di/extension/core.php index 26aa325bdd..701ae453d1 100644 --- a/phpBB/includes/di/extension/core.php +++ b/phpBB/includes/di/extension/core.php @@ -48,8 +48,6 @@ class phpbb_di_extension_core extends Extension * @param ContainerBuilder $container A ContainerBuilder instance * * @throws InvalidArgumentException When provided tag is not defined in this extension - * - * @api */ public function load(array $config, ContainerBuilder $container) { @@ -66,8 +64,6 @@ class phpbb_di_extension_core extends Extension * This alias is also the mandatory prefix to use when using YAML. * * @return string The alias - * - * @api */ public function getAlias() { diff --git a/phpBB/includes/di/extension/ext.php b/phpBB/includes/di/extension/ext.php index 2539ff5667..5898989717 100644 --- a/phpBB/includes/di/extension/ext.php +++ b/phpBB/includes/di/extension/ext.php @@ -42,8 +42,6 @@ class phpbb_di_extension_ext extends Extension * @param ContainerBuilder $container A ContainerBuilder instance * * @throws InvalidArgumentException When provided tag is not defined in this extension - * - * @api */ public function load(array $config, ContainerBuilder $container) { @@ -63,8 +61,6 @@ class phpbb_di_extension_ext extends Extension * This alias is also the mandatory prefix to use when using YAML. * * @return string The alias - * - * @api */ public function getAlias() { From 3e4d3761fdec878758e43779eab124816596c8aa Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 14:18:11 +0100 Subject: [PATCH 24/29] [ticket/11152] Rename collection to collection_pass PHPBB3-11152 --- phpBB/common.php | 2 +- phpBB/download/file.php | 2 +- phpBB/includes/di/pass/{collection.php => collection_pass.php} | 2 +- phpBB/install/database_update.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename phpBB/includes/di/pass/{collection.php => collection_pass.php} (93%) diff --git a/phpBB/common.php b/phpBB/common.php index b435970692..6dc018c5c2 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -106,7 +106,7 @@ $phpbb_container = phpbb_create_dumped_container_unless_debug( new phpbb_di_extension_core($phpbb_root_path), ), array( - new phpbb_di_pass_collection('cron.task_collection', 'cron.task'), + new phpbb_di_pass_collection_pass('cron.task_collection', 'cron.task'), ), $phpbb_root_path, $phpEx diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 5ef64e6ecc..ac0f87eb3a 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -65,7 +65,7 @@ if (isset($_GET['avatar'])) new phpbb_di_extension_core($phpbb_root_path), ), array( - new phpbb_di_pass_collection('cron.task_collection', 'cron.task'), + new phpbb_di_pass_collection_pass('cron.task_collection', 'cron.task'), ), $phpbb_root_path, $phpEx diff --git a/phpBB/includes/di/pass/collection.php b/phpBB/includes/di/pass/collection_pass.php similarity index 93% rename from phpBB/includes/di/pass/collection.php rename to phpBB/includes/di/pass/collection_pass.php index 09e4b08f62..70a44d1d51 100644 --- a/phpBB/includes/di/pass/collection.php +++ b/phpBB/includes/di/pass/collection_pass.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -class phpbb_di_pass_collection implements CompilerPassInterface +class phpbb_di_pass_collection_pass implements CompilerPassInterface { private $collection_service; private $service_tag; diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index add59b3c85..1940daf334 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -123,7 +123,7 @@ $phpbb_container = phpbb_create_dumped_container_unless_debug( new phpbb_di_extension_core($phpbb_root_path), ), array( - new phpbb_di_pass_collection('cron.task_collection', 'cron.task'), + new phpbb_di_pass_collection_pass('cron.task_collection', 'cron.task'), ), $phpbb_root_path, $phpEx From 09781a96bc10fd659a4746055762d849905b8b71 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 16:28:28 +0100 Subject: [PATCH 25/29] [ticket/11152] Use realpath in container extensions consistently PHPBB-11152 --- phpBB/includes/di/extension/core.php | 12 ++++++------ phpBB/includes/di/extension/ext.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/di/extension/core.php b/phpBB/includes/di/extension/core.php index 701ae453d1..7dfdd6782a 100644 --- a/phpBB/includes/di/extension/core.php +++ b/phpBB/includes/di/extension/core.php @@ -29,16 +29,16 @@ class phpbb_di_extension_core extends Extension * phpBB Root path * @var string */ - protected $phpbb_root_path; + protected $root_path; /** * Constructor * - * @param string $phpbb_root_path Root path + * @param string $root_path Root path */ - public function __construct($phpbb_root_path) + public function __construct($root_path) { - $this->phpbb_root_path = $phpbb_root_path; + $this->root_path = $root_path; } /** @@ -51,9 +51,9 @@ class phpbb_di_extension_core extends Extension */ public function load(array $config, ContainerBuilder $container) { - if (file_exists($this->phpbb_root_path . 'config/services.yml')) + if (file_exists($this->root_path . 'config/services.yml')) { - $loader = new YamlFileLoader($container, new FileLocator(realpath($this->phpbb_root_path . 'config'))); + $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->root_path . 'config'))); $loader->load('services.yml'); } } diff --git a/phpBB/includes/di/extension/ext.php b/phpBB/includes/di/extension/ext.php index 5898989717..e76c543ee1 100644 --- a/phpBB/includes/di/extension/ext.php +++ b/phpBB/includes/di/extension/ext.php @@ -49,7 +49,7 @@ class phpbb_di_extension_ext extends Extension { if (file_exists($path . '/config/services.yml')) { - $loader = new YamlFileLoader($container, new FileLocator($path . '/config')); + $loader = new YamlFileLoader($container, new FileLocator(phpbb_real_path($path . '/config'))); $loader->load('services.yml'); } } From 844770d223eca4fe509a00e6e979be7cb58eadd5 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 17:43:12 +0100 Subject: [PATCH 26/29] [ticket/11152] Remove old container processor calls PHPBB3-11152 --- phpBB/download/file.php | 7 ------- phpBB/install/database_update.php | 7 ------- 2 files changed, 14 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index ac0f87eb3a..95b20a88d2 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -98,13 +98,6 @@ if (isset($_GET['avatar'])) $phpbb_extension_manager = $phpbb_container->get('ext.manager'); $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); - $ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); - foreach ($ids as $id) - { - $processor = $phpbb_container->get($id); - $processor->process($phpbb_container); - } - // worst-case default $browser = strtolower($request->header('User-Agent', 'msie 6.0')); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 1940daf334..0121ccab1e 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -142,13 +142,6 @@ $user = $phpbb_container->get('user'); $auth = $phpbb_container->get('auth'); $db = $phpbb_container->get('dbal.conn'); -$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); -foreach ($ids as $id) -{ - $processor = $phpbb_container->get($id); - $processor->process($phpbb_container); -} - // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function From 5616972195b89324daa567b9a771aa49734af11c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 17:53:24 +0100 Subject: [PATCH 27/29] [ticket/11152] Throw error if services.yml is missing PHPBB3-11152 --- phpBB/includes/di/extension/core.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/di/extension/core.php b/phpBB/includes/di/extension/core.php index 7dfdd6782a..9c36ba2fc4 100644 --- a/phpBB/includes/di/extension/core.php +++ b/phpBB/includes/di/extension/core.php @@ -51,11 +51,8 @@ class phpbb_di_extension_core extends Extension */ public function load(array $config, ContainerBuilder $container) { - if (file_exists($this->root_path . 'config/services.yml')) - { - $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->root_path . 'config'))); - $loader->load('services.yml'); - } + $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->root_path . 'config'))); + $loader->load('services.yml'); } /** From 00417fc723073a9e8acefe4a8a7660bf25017201 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 17:54:54 +0100 Subject: [PATCH 28/29] [ticket/11152] Compile the install container PHPBB3-11152 --- phpBB/includes/functions_container.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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; } From 1bf7f0bde73a8528f77b5f9cfffd6f113afcf63d Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 17:56:09 +0100 Subject: [PATCH 29/29] [ticket/11152] Basic tests for the container functions PHPBB3-11152 --- tests/di/create_container_test.php | 72 ++++++++++++++++++++++++++++++ tests/di/fixtures/config.php | 11 +++++ 2 files changed, 83 insertions(+) create mode 100644 tests/di/create_container_test.php create mode 100644 tests/di/fixtures/config.php diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php new file mode 100644 index 0000000000..c2b8a0fc0b --- /dev/null +++ b/tests/di/create_container_test.php @@ -0,0 +1,72 @@ +assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + } + + public function test_phpbb_create_install_container() + { + $phpbb_root_path = __DIR__ . '/../../phpBB/'; + $extensions = array( + new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'), + new phpbb_di_extension_core($phpbb_root_path), + ); + $container = phpbb_create_install_container($phpbb_root_path, 'php'); + + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + $this->assertTrue($container->isFrozen()); + } + + public function test_phpbb_create_compiled_container() + { + $phpbb_root_path = __DIR__ . '/../../phpBB/'; + $extensions = array( + new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'), + new phpbb_di_extension_core($phpbb_root_path), + ); + $container = phpbb_create_compiled_container($extensions, array(), $phpbb_root_path, 'php'); + + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + $this->assertTrue($container->isFrozen()); + } +} + +class dbal_container_mock extends dbal +{ + public function sql_connect() + { + } + + public function sql_query() + { + } + + public function sql_fetchrow() + { + } + + public function sql_freeresult() + { + } +} diff --git a/tests/di/fixtures/config.php b/tests/di/fixtures/config.php new file mode 100644 index 0000000000..5033d2dc9f --- /dev/null +++ b/tests/di/fixtures/config.php @@ -0,0 +1,11 @@ +