From bbcf0f467c3cd83f1513a55112f373b2a33bf08f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 5 Aug 2020 06:49:01 -0700 Subject: [PATCH] (REF) CRM_Core_Resources_Strings - Move instance into container --- CRM/Core/Resources.php | 6 +++--- Civi/Core/Container.php | 7 ++++++- tests/phpunit/CRM/Core/ResourcesTest.php | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 265112d8f9..3e736d3c05 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -135,13 +135,13 @@ class CRM_Core_Resources { * * @param CRM_Extension_Mapper $extMapper * Map extension names to their base path or URLs. - * @param CRM_Utils_Cache_Interface $cache + * @param CRM_Core_Resources_Strings $strings * JS-localization cache. * @param string|null $cacheCodeKey Random code to append to resource URLs; changing the code forces clients to reload resources */ - public function __construct($extMapper, $cache, $cacheCodeKey = NULL) { + public function __construct($extMapper, $strings, $cacheCodeKey = NULL) { $this->extMapper = $extMapper; - $this->strings = new CRM_Core_Resources_Strings($cache); + $this->strings = $strings; $this->cacheCodeKey = $cacheCodeKey; if ($cacheCodeKey !== NULL) { $this->cacheCode = Civi::settings()->get($cacheCodeKey); diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 5b96e40ef0..ee8b214e7f 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -237,6 +237,11 @@ class Container { [new Reference('service_container')] ))->setFactory([new Reference(self::SELF), 'createResources'])->setPublic(TRUE); + $container->setDefinition('resources.js_strings', new Definition( + 'CRM_Core_Resources_Strings', + [new Reference('cache.js_strings')] + ))->setPublic(TRUE); + $container->setDefinition('prevnext', new Definition( 'CRM_Core_PrevNextCache_Interface', [new Reference('service_container')] @@ -450,7 +455,7 @@ class Container { $sys = \CRM_Extension_System::singleton(); return new \CRM_Core_Resources( $sys->getMapper(), - $container->get('cache.js_strings'), + new \CRM_Core_Resources_Strings($container->get('cache.js_strings')), \CRM_Core_Config::isUpgradeMode() ? NULL : 'resCacheCode' ); } diff --git a/tests/phpunit/CRM/Core/ResourcesTest.php b/tests/phpunit/CRM/Core/ResourcesTest.php index 6c1fc7dd1f..629ba4f803 100644 --- a/tests/phpunit/CRM/Core/ResourcesTest.php +++ b/tests/phpunit/CRM/Core/ResourcesTest.php @@ -40,7 +40,7 @@ class CRM_Core_ResourcesTest extends CiviUnitTestCase { list ($this->basedir, $this->container, $this->mapper) = $this->_createMapper(); $cache = new CRM_Utils_Cache_Arraycache([]); - $this->res = new CRM_Core_Resources($this->mapper, $cache, NULL); + $this->res = new CRM_Core_Resources($this->mapper, new CRM_Core_Resources_Strings($cache), NULL); $this->res->setCacheCode('resTest'); CRM_Core_Resources::singleton($this->res); -- 2.25.1