class ServiceWithDependency in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/new_dependency_test/src/ServiceWithDependency.php \Drupal\new_dependency_test\ServiceWithDependency
- 9 core/modules/system/tests/modules/new_dependency_test/src/ServiceWithDependency.php \Drupal\new_dependency_test\ServiceWithDependency
Service that gets the other service of the same module injected.
This service indirectly depends on a not-yet-defined service.
Hierarchy
- class \Drupal\new_dependency_test\ServiceWithDependency
Expanded class hierarchy of ServiceWithDependency
1 string reference to 'ServiceWithDependency'
- new_dependency_test.services.yml in core/
modules/ system/ tests/ modules/ new_dependency_test/ new_dependency_test.services.yml - core/modules/system/tests/modules/new_dependency_test/new_dependency_test.services.yml
5 services use ServiceWithDependency
- new_dependency_test.alias_dependency in core/
modules/ system/ tests/ modules/ new_dependency_test/ new_dependency_test.services.yml - Drupal\new_dependency_test\ServiceWithDependency
- new_dependency_test.alias_dependency2 in core/
modules/ system/ tests/ modules/ new_dependency_test/ new_dependency_test.services.yml - Drupal\new_dependency_test\ServiceWithDependency
- new_dependency_test.hard_dependency in core/
modules/ system/ tests/ modules/ new_dependency_test/ new_dependency_test.services.yml - Drupal\new_dependency_test\ServiceWithDependency
- new_dependency_test.optional_dependency in core/
modules/ system/ tests/ modules/ new_dependency_test/ new_dependency_test.services.yml - Drupal\new_dependency_test\ServiceWithDependency
- new_dependency_test.recursion in core/
modules/ system/ tests/ modules/ new_dependency_test/ new_dependency_test.services.yml - Drupal\new_dependency_test\ServiceWithDependency
File
- core/
modules/ system/ tests/ modules/ new_dependency_test/ src/ ServiceWithDependency.php, line 10
Namespace
Drupal\new_dependency_testView source
class ServiceWithDependency {
/**
* The injected service.
*
* @var \Drupal\new_dependency_test\InjectedService
*/
protected $service;
/**
* ServiceWithDependency constructor.
*
* @param \Drupal\new_dependency_test\InjectedService|null $service
* The service of the same module which has the new dependency.
*/
public function __construct(InjectedService $service = NULL) {
$this->service = $service;
}
/**
* Gets a greeting from the injected service and adds to it.
*
* @return string
* The greeting.
*/
public function greet() {
if (isset($this->service)) {
return $this->service
->greet() . ' World';
}
return 'Sorry, no service.';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ServiceWithDependency:: |
protected | property | The injected service. | |
ServiceWithDependency:: |
public | function | Gets a greeting from the injected service and adds to it. | |
ServiceWithDependency:: |
public | function | ServiceWithDependency constructor. |