From: Tim Otten Date: Thu, 18 Oct 2018 02:33:01 +0000 (-0700) Subject: CRM_Core_Resources - Allow container to swap the implementation X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=223ba0251b91be43d429e8b392079291feea7a98;p=civicrm-core.git CRM_Core_Resources - Allow container to swap the implementation --- 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