ServiceWithDependency.php
Same filename in other branches
Namespace
Drupal\new_dependency_testFile
-
core/
modules/ system/ tests/ modules/ new_dependency_test/ src/ ServiceWithDependency.php
View source
<?php
declare (strict_types=1);
namespace Drupal\new_dependency_test;
/**
* Service that gets the other service of the same module injected.
*
* This service indirectly depends on a not-yet-defined service.
*/
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.';
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
ServiceWithDependency | Service that gets the other service of the same module injected. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.