From 223ba0251b91be43d429e8b392079291feea7a98 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 17 Oct 2018 19:33:01 -0700 Subject: [PATCH] CRM_Core_Resources - Allow container to swap the implementation --- CRM/Core/Resources.php | 8 +------- Civi/Core/Container.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 7436cb682a..b8e10ff046 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -115,13 +115,7 @@ class CRM_Core_Resources { self::$_singleton = $instance; } if (self::$_singleton === NULL) { - $sys = CRM_Extension_System::singleton(); - $cache = Civi::cache('js_strings'); - self::$_singleton = new CRM_Core_Resources( - $sys->getMapper(), - $cache, - CRM_Core_Config::isUpgradeMode() ? NULL : 'resCacheCode' - ); + self::$_singleton = Civi::service('resources'); } return self::$_singleton; } diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index cdaabecc91..9ca66a67c1 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -201,7 +201,6 @@ class Container { // Expose legacy singletons as services in the container. $singletons = array( - 'resources' => 'CRM_Core_Resources', 'httpClient' => 'CRM_Utils_HttpClient', 'cache.default' => 'CRM_Utils_Cache', 'i18n' => 'CRM_Core_I18n', @@ -216,6 +215,11 @@ class Container { } $container->setAlias('cache.short', 'cache.default'); + $container->setDefinition('resources', new Definition( + 'CRM_Core_Resources', + [new Reference('service_container')] + ))->setFactory(array(new Reference(self::SELF), 'createResources')); + $container->setDefinition('prevnext', new Definition( 'CRM_Core_PrevNextCache_Interface', [new Reference('service_container')] @@ -411,6 +415,19 @@ class Container { return $kernel; } + /** + * @param ContainerInterface $container + * @return \CRM_Core_Resources + */ + public static function createResources($container) { + $sys = \CRM_Extension_System::singleton(); + return new \CRM_Core_Resources( + $sys->getMapper(), + $container->get('cache.js_strings'), + \CRM_Core_Config::isUpgradeMode() ? NULL : 'resCacheCode' + ); + } + /** * @param ContainerInterface $container * @return \CRM_Core_PrevNextCache_Interface -- 2.25.1