From f48709f5bb8fb1b916d308e3b4bb06bc96d08611 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 19 Oct 2012 19:53:29 -0400 Subject: [feature/compiled-dic] Compile the DI Container into a cached class PHPBB3-11152 --- phpBB/includes/cache/driver/file.php | 2 +- phpBB/includes/cache/driver/memory.php | 2 +- phpBB/includes/di/extension/config.php | 87 ++++++++++++++++++ phpBB/includes/di/extension/core.php | 76 ++++++++++++++++ phpBB/includes/di/extension/ext.php | 73 ++++++++++++++++ phpBB/includes/di/processor/config.php | 76 ---------------- 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 ------------------ phpBB/includes/extension/controller_interface.php | 31 ------- phpBB/includes/functions.php | 102 ++++++++++++++++++++++ 14 files changed, 508 insertions(+), 277 deletions(-) create mode 100644 phpBB/includes/di/extension/config.php 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/config.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 (limited to 'phpBB/includes') 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/extension/config.php b/phpBB/includes/di/extension/config.php new file mode 100644 index 0000000000..b9c752c5de --- /dev/null +++ b/phpBB/includes/di/extension/config.php @@ -0,0 +1,87 @@ +config_file = $config_file; + } + + /** + * 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) + { + require($this->config_file); + + $container->setParameter('core.table_prefix', $table_prefix); + $container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); + $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); + $container->setParameter('dbal.dbhost', $dbhost); + $container->setParameter('dbal.dbuser', $dbuser); + $container->setParameter('dbal.dbpasswd', $dbpasswd); + $container->setParameter('dbal.dbname', $dbname); + $container->setParameter('dbal.dbport', $dbport); + $container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); + } + + /** + * 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)) + { + return 'phpbb_cache_driver_'.$acm_type; + } + + return $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/config.php b/phpBB/includes/di/processor/config.php deleted file mode 100644 index 22b6252a6d..0000000000 --- a/phpBB/includes/di/processor/config.php +++ /dev/null @@ -1,76 +0,0 @@ -config_file = $config_file; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } - - /** - * @inheritdoc - */ - public function process(ContainerBuilder $container) - { - require $this->config_file; - - $container->setParameter('core.root_path', $this->phpbb_root_path); - $container->setParameter('core.php_ext', $this->php_ext); - - $container->setParameter('core.table_prefix', $table_prefix); - $container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); - $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); - $container->setParameter('dbal.dbhost', $dbhost); - $container->setParameter('dbal.dbuser', $dbuser); - $container->setParameter('dbal.dbpasswd', $dbpasswd); - $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); - } - - protected function fix_acm_type($acm_type) - { - if (preg_match('#^[a-z]+$#', $acm_type)) - { - return 'phpbb_cache_driver_'.$acm_type; - } - - return $acm_type; - } -} 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; +} -- cgit v1.2.1 From 44ba84087755b66a2ce5bed06bd8558628239ab3 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 10:23:04 -0400 Subject: [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(-) (limited to 'phpBB/includes') 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; } -- cgit v1.2.1 From d88e11413ac89ac2bfda303dd4ecaacef6dc8c0f Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 10:46:38 -0400 Subject: [feature/compiled-dic] Remove unused service definition PHPBB3-11152 --- phpBB/includes/functions.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') 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); -- cgit v1.2.1 From 6d40b81dda242f5f07fe1e01430d70e6879d1885 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 10:58:35 -0400 Subject: [feature/compiled-dic] Remove unused function parameter PHPBB3-11152 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') 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")) -- cgit v1.2.1 From b20d852b7fc43431ade40ee97fd5ece5e3271d5d Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 20 Oct 2012 16:57:21 -0400 Subject: [feature/compiled-dic] Remove HttpKernel-related stuff These things should be added in the Controller PR instead. PHPBB3-11152 --- phpBB/includes/event/kernel_compiler_pass.php | 72 -------------------- phpBB/includes/event/kernel_subscriber.php | 94 --------------------------- 2 files changed, 166 deletions(-) delete mode 100644 phpBB/includes/event/kernel_compiler_pass.php delete mode 100644 phpBB/includes/event/kernel_subscriber.php (limited to 'phpBB/includes') 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', - ); - } -} -- cgit v1.2.1 From cb2725dd5a04118de8628e10f940e926f4fa8fa1 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 21 Oct 2012 16:09:43 -0400 Subject: [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/includes/cron/task/collection.php | 72 +++++++++++++++++++++++++++++++++ phpBB/includes/cron/task/provider.php | 27 ++++++++----- phpBB/includes/di/pass/cron.php | 38 +++++++++++++++++ 3 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 phpBB/includes/cron/task/collection.php create mode 100644 phpBB/includes/di/pass/cron.php (limited to 'phpBB/includes') 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)); + } + } +} -- cgit v1.2.1 From a6428c8dc3c211675da5e7e58503849791d2d3e5 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 22 Oct 2012 11:17:49 -0400 Subject: [feature/compiled-dic] Fix cron tasks again PHPBB3-11152 --- phpBB/includes/cron/task/collection.php | 51 +++++++------------------ phpBB/includes/cron/task/provider.php | 66 --------------------------------- phpBB/includes/di/pass/cron.php | 2 +- 3 files changed, 15 insertions(+), 104 deletions(-) delete mode 100644 phpBB/includes/cron/task/provider.php (limited to 'phpBB/includes') 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 - * - * @param mixed $offset Array offset - */ - public function offsetExists($offset) - { - return isset($this->tasks[$offset]); - } - - /** - * ArrayAccess method - * - * @param mixed $offset Array offset - */ - public function offsetGet($offset) - { - return $this->offsetExists($offset) ? $this->tasks[$offset] : null; - } - - /** - * ArrayAccess method + * Constructor * - * @param mixed $offset Array offset - * @param mixed $value New value + * @param TaggedContainerInterface $container Container object */ - public function offsetSet($offset, $value) + public function __construct(TaggedContainerInterface $container) { - if ($offset === null) - { - $this->tasks[] = $value; - } - else - { - $this->tasks[$offset] = $value; - } + $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 offsetUnset($offset) + public function add($name) { - $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)); } } } -- cgit v1.2.1 From af3f07d8c9d79b305f34eb19aa100786d4a3faf8 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 22 Oct 2012 12:17:06 -0400 Subject: [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(-) (limited to 'phpBB/includes') 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; } -- cgit v1.2.1 From c16bb2b2c62f3fa68716b40745cba437cebe5433 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 2 Nov 2012 16:40:12 -0400 Subject: [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(-) (limited to 'phpBB/includes') 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; -- cgit v1.2.1 From 2de8827b1e35d7e522303cadf37da4878bdc89a3 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 2 Nov 2012 16:42:35 -0400 Subject: [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(-) (limited to 'phpBB/includes') 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; } -- cgit v1.2.1 From 3f2cbaac34e1cf126c73bebc7dcc3cdbd203d1b2 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 2 Nov 2012 18:36:52 -0400 Subject: [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(-) (limited to 'phpBB/includes') 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; } -- cgit v1.2.1 From 897e8f2e8361839a92acae7e77225ef212e44647 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 9 Nov 2012 23:00:44 +0100 Subject: [ticket/11152] Move container functions to a separate function file PHPBB3-11152 --- phpBB/includes/functions.php | 105 ----------------------------- phpBB/includes/functions_container.php | 119 +++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 105 deletions(-) create mode 100644 phpBB/includes/functions_container.php (limited to 'phpBB/includes') 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; +} -- cgit v1.2.1 From 38e1c4ec5d363900285a6a72ee78f4f2e2943bd0 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 09:55:17 +0100 Subject: [ticket/11152] Use relative root path in container, one dumped container per path PHPBB3-11152 --- phpBB/includes/functions_container.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index 88adc64882..8e2c9606cd 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -78,26 +78,22 @@ function phpbb_create_install_container($phpbb_root_path, $php_ext) function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $php_ext) { // Check for our cached container; if it exists, use it - if (file_exists("{$phpbb_root_path}cache/container.$php_ext")) + $container_filename = phpbb_container_filename($phpbb_root_path, $php_ext); + if (file_exists($container_filename)) { - require("{$phpbb_root_path}cache/container.$php_ext"); + require($container_filename); return new phpbb_cache_container(); } - // We must use an absolute path in the container because we cannot - // change the value at runtime when accessing it in different - // directory levels. - $phpbb_absolute_path = phpbb_realpath($phpbb_root_path) . '/'; - // Create a temporary container for access to the ext.manager service - $tmp_container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext); + $tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); $tmp_container->compile(); // Now pass the enabled extension paths into the ext compiler extension $extensions[] = new phpbb_di_extension_ext($tmp_container->get('ext.manager')->all_enabled()); // Create the final container to be compiled and cached - $container = phpbb_create_container($extensions, $phpbb_absolute_path, $php_ext); + $container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); // Compile the container foreach ($passes as $pass) @@ -113,7 +109,13 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', )); - $file = file_put_contents("{$phpbb_absolute_path}cache/container.{$php_ext}", $cached_container_dump); + file_put_contents($container_filename, $cached_container_dump); return $container; } + +function phpbb_container_filename($phpbb_root_path, $php_ext) +{ + $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); + return $phpbb_root_path . 'cache/' . $filename . '_container.' . $php_ext; +} -- cgit v1.2.1 From 798c006e7fe55bc1de30e42a4c25e8c74911c865 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 16:38:19 +0100 Subject: [ticket/11152] Convert cron_task_collection to generic di_service_collection PHPBB3-11152 --- phpBB/includes/cron/task/collection.php | 49 -------------------------------- phpBB/includes/di/service_collection.php | 49 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 49 deletions(-) delete mode 100644 phpBB/includes/cron/task/collection.php create mode 100644 phpBB/includes/di/service_collection.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/task/collection.php b/phpBB/includes/cron/task/collection.php deleted file mode 100644 index 84607dc28d..0000000000 --- a/phpBB/includes/cron/task/collection.php +++ /dev/null @@ -1,49 +0,0 @@ -container = $container; - } - - /** - * Add a cron task to the collection - * - * @param string $name The service name of the cron task - * @return null - */ - public function add($name) - { - $task = $this->container->get($name); - $task->set_name($name); - $this->offsetSet($name, $task); - } -} diff --git a/phpBB/includes/di/service_collection.php b/phpBB/includes/di/service_collection.php new file mode 100644 index 0000000000..60323c8dba --- /dev/null +++ b/phpBB/includes/di/service_collection.php @@ -0,0 +1,49 @@ +container = $container; + } + + /** + * Add a service to the collection + * + * @param string $name The service name + * @return null + */ + public function add($name) + { + $task = $this->container->get($name); + $task->set_name($name); + $this->offsetSet($name, $task); + } +} -- cgit v1.2.1 From 231d743ba9966e8304e0dd226ebf5eb7fb3b70d8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 23:34:27 +0100 Subject: [ticket/11152] Change phpbb_di_pass_cron to generic phpbb_di_pass_collection PHPBB3-11152 --- phpBB/includes/di/pass/collection.php | 47 +++++++++++++++++++++++++++++++++++ phpBB/includes/di/pass/cron.php | 38 ---------------------------- 2 files changed, 47 insertions(+), 38 deletions(-) create mode 100644 phpBB/includes/di/pass/collection.php delete mode 100644 phpBB/includes/di/pass/cron.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/pass/collection.php b/phpBB/includes/di/pass/collection.php new file mode 100644 index 0000000000..09e4b08f62 --- /dev/null +++ b/phpBB/includes/di/pass/collection.php @@ -0,0 +1,47 @@ +collection_service = $collection_service; + $this->service_tag = $service_tag; + } + + /** + * Modify the container before it is passed to the rest of the code + * + * @param ContainerBuilder $container ContainerBuilder object + * @return null + */ + public function process(ContainerBuilder $container) + { + $definition = $container->getDefinition($this->collection_service); + + foreach ($container->findTaggedServiceIds($this->service_tag) as $id => $data) + { + $definition->addMethodCall('add', array($id)); + } + } +} diff --git a/phpBB/includes/di/pass/cron.php b/phpBB/includes/di/pass/cron.php deleted file mode 100644 index 53fe0a61c8..0000000000 --- a/phpBB/includes/di/pass/cron.php +++ /dev/null @@ -1,38 +0,0 @@ -getDefinition('cron.task_collection'); - - foreach ($container->findTaggedServiceIds('cron.task') as $id => $data) - { - $definition->addMethodCall('add', array($id)); - } - } -} -- cgit v1.2.1 From 8851b797fbf0f1b4120aa4d3ae713711e01ef98f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 23:35:52 +0100 Subject: [ticket/11152] Create separate function for debug-dependent container PHPBB3-11152 --- phpBB/includes/functions_container.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index 8e2c9606cd..e31fe381ac 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -77,14 +77,6 @@ function phpbb_create_install_container($phpbb_root_path, $php_ext) */ function phpbb_create_compiled_container(array $extensions, array $passes, $phpbb_root_path, $php_ext) { - // Check for our cached container; if it exists, use it - $container_filename = phpbb_container_filename($phpbb_root_path, $php_ext); - if (file_exists($container_filename)) - { - require($container_filename); - return new phpbb_cache_container(); - } - // Create a temporary container for access to the ext.manager service $tmp_container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); $tmp_container->compile(); @@ -102,6 +94,21 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb } $container->compile(); + return $container; +} + +function phpbb_create_dumped_container(array $extensions, array $passes, $phpbb_root_path, $php_ext) +{ + // Check for our cached container; if it exists, use it + $container_filename = phpbb_container_filename($phpbb_root_path, $php_ext); + if (file_exists($container_filename)) + { + require($container_filename); + return new phpbb_cache_container(); + } + + $container = phpbb_create_compiled_container($extensions, $passes, $phpbb_root_path, $php_ext); + // Lastly, we create our cached container class $dumper = new PhpDumper($container); $cached_container_dump = $dumper->dump(array( @@ -114,6 +121,15 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb return $container; } +function phpbb_create_dumped_container_unless_debug(array $extensions, array $passes, $phpbb_root_path, $php_ext) +{ + if (defined('DEBUG')) { + return phpbb_create_compiled_container($extensions, $passes, $phpbb_root_path, $php_ext); + } + + return phpbb_create_dumped_container($extensions, $passes, $phpbb_root_path, $php_ext); +} + function phpbb_container_filename($phpbb_root_path, $php_ext) { $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); -- cgit v1.2.1 From bdbf7d5de61c902c54fa5882440a5334ac7ad24f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 23:36:13 +0100 Subject: [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(-) (limited to 'phpBB/includes') 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() { -- cgit v1.2.1 From 3e4d3761fdec878758e43779eab124816596c8aa Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 14:18:11 +0100 Subject: [ticket/11152] Rename collection to collection_pass PHPBB3-11152 --- phpBB/includes/di/pass/collection.php | 47 ------------------------------ phpBB/includes/di/pass/collection_pass.php | 47 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 47 deletions(-) delete mode 100644 phpBB/includes/di/pass/collection.php create mode 100644 phpBB/includes/di/pass/collection_pass.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/pass/collection.php b/phpBB/includes/di/pass/collection.php deleted file mode 100644 index 09e4b08f62..0000000000 --- a/phpBB/includes/di/pass/collection.php +++ /dev/null @@ -1,47 +0,0 @@ -collection_service = $collection_service; - $this->service_tag = $service_tag; - } - - /** - * Modify the container before it is passed to the rest of the code - * - * @param ContainerBuilder $container ContainerBuilder object - * @return null - */ - public function process(ContainerBuilder $container) - { - $definition = $container->getDefinition($this->collection_service); - - foreach ($container->findTaggedServiceIds($this->service_tag) as $id => $data) - { - $definition->addMethodCall('add', array($id)); - } - } -} diff --git a/phpBB/includes/di/pass/collection_pass.php b/phpBB/includes/di/pass/collection_pass.php new file mode 100644 index 0000000000..70a44d1d51 --- /dev/null +++ b/phpBB/includes/di/pass/collection_pass.php @@ -0,0 +1,47 @@ +collection_service = $collection_service; + $this->service_tag = $service_tag; + } + + /** + * Modify the container before it is passed to the rest of the code + * + * @param ContainerBuilder $container ContainerBuilder object + * @return null + */ + public function process(ContainerBuilder $container) + { + $definition = $container->getDefinition($this->collection_service); + + foreach ($container->findTaggedServiceIds($this->service_tag) as $id => $data) + { + $definition->addMethodCall('add', array($id)); + } + } +} -- cgit v1.2.1 From 09781a96bc10fd659a4746055762d849905b8b71 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 16:28:28 +0100 Subject: [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(-) (limited to 'phpBB/includes') 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'); } } -- cgit v1.2.1 From 5616972195b89324daa567b9a771aa49734af11c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 17:53:24 +0100 Subject: [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(-) (limited to 'phpBB/includes') 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'); } /** -- cgit v1.2.1 From 00417fc723073a9e8acefe4a8a7660bf25017201 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Nov 2012 17:54:54 +0100 Subject: [ticket/11152] Compile the install container PHPBB3-11152 --- phpBB/includes/functions_container.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index e31fe381ac..1de1d9f7ea 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -53,16 +53,19 @@ function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext) */ function phpbb_create_install_container($phpbb_root_path, $php_ext) { - // We have to do it like this instead of with extensions - $container = new ContainerBuilder(); - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); - $loader->load('services.yml'); + $core = new phpbb_di_extension_core($phpbb_root_path); + $container = phpbb_create_container(array($core), $phpbb_root_path, $php_ext); $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $php_ext); + $container->setParameter('core.table_prefix', ''); + + $container->register('dbal.conn')->setSynthetic(true); $container->setAlias('cache.driver', 'cache.driver.install'); + $container->compile(); + return $container; } -- cgit v1.2.1 From d2a051cdd4269fd5749bdd4e7619fc5176a510a8 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 11 Nov 2012 18:39:24 +0100 Subject: [ticket/11193] Instantiate a single collection_pass for all collections PHPBB3-11193 --- phpBB/includes/di/pass/collection_pass.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/pass/collection_pass.php b/phpBB/includes/di/pass/collection_pass.php index 70a44d1d51..d5b82f61da 100644 --- a/phpBB/includes/di/pass/collection_pass.php +++ b/phpBB/includes/di/pass/collection_pass.php @@ -18,17 +18,13 @@ if (!defined('IN_PHPBB')) use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +/** +* Appends an add method call to the definition of each collection service for +* the services tagged with the appropriate name defined in the collection's +* service_collection tag. +*/ class phpbb_di_pass_collection_pass 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 * @@ -37,11 +33,14 @@ class phpbb_di_pass_collection_pass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { - $definition = $container->getDefinition($this->collection_service); - - foreach ($container->findTaggedServiceIds($this->service_tag) as $id => $data) + foreach ($container->findTaggedServiceIds('service_collection') as $id => $data) { - $definition->addMethodCall('add', array($id)); + $definition = $container->getDefinition($id); + + foreach ($container->findTaggedServiceIds($data['tag']) as $service_id => $service_data) + { + $definition->addMethodCall('add', array($service_id)); + } } } } -- cgit v1.2.1 From 09ec65cb9b9d061d7e9c99d569a99cbe905792ca Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 12 Nov 2012 01:01:02 +0100 Subject: [ticket/11194] Service tag data is stored in an array so access it correctly PHPBB3-11194 --- phpBB/includes/di/pass/collection_pass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/pass/collection_pass.php b/phpBB/includes/di/pass/collection_pass.php index d5b82f61da..63a5c7dfc4 100644 --- a/phpBB/includes/di/pass/collection_pass.php +++ b/phpBB/includes/di/pass/collection_pass.php @@ -37,7 +37,7 @@ class phpbb_di_pass_collection_pass implements CompilerPassInterface { $definition = $container->getDefinition($id); - foreach ($container->findTaggedServiceIds($data['tag']) as $service_id => $service_data) + foreach ($container->findTaggedServiceIds($data[0]['tag']) as $service_id => $service_data) { $definition->addMethodCall('add', array($service_id)); } -- cgit v1.2.1