From aa0195698f8d5b4a62abf081a3b860814279f9b4 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 16 Aug 2022 14:46:05 -0700 Subject: [PATCH] (REF) Civi\Core\Container - Extract method for overriding the active container --- Civi/Core/Container.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index bf7c4672ca..e0f205c0ce 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -642,21 +642,30 @@ class Container { $runtime->includeCustomPath(); $c = new self(); - $container = $c->loadContainer(); - foreach ($bootServices as $name => $obj) { - $container->set($name, $obj); - } - \Civi::$statics[__CLASS__]['container'] = $container; - // Ensure all container-based serivces have a chance to add their listeners. - // Without this, it's a matter of happenstance (dependent upon particular page-request/configuration/etc). - $container->get('dispatcher'); - + static::useContainer($c->loadContainer()); } else { $bootServices['dispatcher.boot']->setDispatchPolicy(\CRM_Core_Config::isUpgradeMode() ? \CRM_Upgrade_DispatchPolicy::pick() : NULL); } } + /** + * Set the active container (over-writing the current container, if defined). + * + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * @internal Intended for bootstrap and unit-testing. + */ + public static function useContainer($container): void { + $bootServices = \Civi::$statics[__CLASS__]['boot']; + foreach ($bootServices as $name => $obj) { + $container->set($name, $obj); + } + \Civi::$statics[__CLASS__]['container'] = $container; + // Ensure all container-based serivces have a chance to add their listeners. + // Without this, it's a matter of happenstance (dependent upon particular page-request/configuration/etc). + $container->get('dispatcher'); + } + /** * @param string $name * -- 2.25.1