Skip to content

Commit

Permalink
CRM_Core_Resources - Allow container to swap the implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Oct 18, 2018
1 parent df466fe commit 223ba02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
8 changes: 1 addition & 7 deletions CRM/Core/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,7 @@ static public function singleton(CRM_Core_Resources $instance = NULL) {
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;
}
Expand Down
19 changes: 18 additions & 1 deletion Civi/Core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ public function createContainer() {

// 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',
Expand All @@ -216,6 +215,11 @@ public function createContainer() {
}
$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')]
Expand Down Expand Up @@ -411,6 +415,19 @@ public function createApiKernel($dispatcher, $magicFunctionProvider) {
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
Expand Down

0 comments on commit 223ba02

Please sign in to comment.