class ExampleClassWithDependencyInjection in Coder 8.3
Same name and namespace in other branches
- 8.3.x tests/DrupalPractice/Objects/drupal8/ExampleClassWithDependencyInjection.php \Drupal\testmodule\ExampleClassWithDependencyInjection
A class which is not a service but has access to the container.
Hierarchy
- class \Drupal\testmodule\ExampleClassWithDependencyInjection implements ContainerInjectionInterface
Expanded class hierarchy of ExampleClassWithDependencyInjection
File
- tests/
DrupalPractice/ Objects/ drupal8/ ExampleClassWithDependencyInjection.php, line 11
Namespace
Drupal\testmoduleView source
class ExampleClassWithDependencyInjection implements ContainerInjectionInterface {
/**
* Using \Drupal here is not allowed, it should be injected instead.
*/
public function test() {
return \Drupal::configFactory();
}
/**
* Loading nodes directly is not allowed, we should use an injected service.
*/
public function test2() {
return Node::load(1);
}
/**
* Global function should not be used, we should use an injected service.
*/
public function test3() {
return format_date(time());
}
/**
* t() should not be used, instead we should use the StringTranslationTrait.
*/
public function test4() {
return t('Test');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContainerInjectionInterface:: |
public static | function | Instantiates a new instance of this class. | 70 |
ExampleClassWithDependencyInjection:: |
public | function | Using \Drupal here is not allowed, it should be injected instead. | |
ExampleClassWithDependencyInjection:: |
public | function | Loading nodes directly is not allowed, we should use an injected service. | |
ExampleClassWithDependencyInjection:: |
public | function | Global function should not be used, we should use an injected service. | |
ExampleClassWithDependencyInjection:: |
public | function | t() should not be used, instead we should use the StringTranslationTrait. |