Commit 9d3d9301 authored by xjm's avatar xjm

Issue #2785355 by timmillwood, dawehner, claudiu.cristea, borisson_: Expose...

Issue #2785355 by timmillwood, dawehner, claudiu.cristea, borisson_: Expose the class resolver on \Drupal
parent ea28d669
......@@ -299,6 +299,23 @@ public static function cache($bin = 'default') {
return static::getContainer()->get('cache.' . $bin);
}
/**
* Retrieves the class resolver.
*
* This is to be used in procedural code such as module files to instantiate
* an object of a class that implements
* \Drupal\Core\DependencyInjection\ContainerInjectionInterface.
*
* One common usecase is to provide a class which contains the actual code
* of a hook implementation, without having to create a service.
*
* @return \Drupal\Core\DependencyInjection\ClassResolverInterface
* The class resolver.
*/
public static function classResolver() {
return static::getContainer()->get('class_resolver');
}
/**
* Returns an expirable key value store collection.
*
......
......@@ -102,7 +102,7 @@ public function testDatabase() {
}
/**
* Tests the service() method.
* Tests the cache() method.
*
* @covers ::cache
*/
......@@ -111,6 +111,16 @@ public function testCache() {
$this->assertNotNull(\Drupal::cache('test'));
}
/**
* Tests the classResolver method.
*
* @covers ::classResolver
*/
public function testClassResolver() {
$this->setMockContainerService('class_resolver');
$this->assertNotNull(\Drupal::classResolver());
}
/**
* Tests the keyValueExpirable() method.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment