You are here

class InjectedService in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/new_dependency_test/src/InjectedService.php \Drupal\new_dependency_test\InjectedService

Generic service with a dependency on a service defined in a new module.

Hierarchy

Expanded class hierarchy of InjectedService

1 string reference to 'InjectedService'
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
1 service uses InjectedService
new_dependency_test.dependent in core/modules/system/tests/modules/new_dependency_test/new_dependency_test.services.yml
Drupal\new_dependency_test\InjectedService

File

core/modules/system/tests/modules/new_dependency_test/src/InjectedService.php, line 10

Namespace

Drupal\new_dependency_test
View source
class InjectedService {

  /**
   * The injected service.
   *
   * @var \Drupal\new_dependency_test_with_service\NewService
   */
  protected $service;

  /**
   * InjectedService constructor.
   *
   * @param \Drupal\new_dependency_test_with_service\NewService $service
   *   The service of the new module.
   */
  public function __construct(NewService $service) {
    $this->service = $service;
  }

  /**
   * Get the simple greeting from the service.
   *
   * @return string
   *   The greeting.
   */
  public function greet() {
    return $this->service
      ->greet();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InjectedService::$service protected property The injected service.
InjectedService::greet public function Get the simple greeting from the service.
InjectedService::__construct public function InjectedService constructor.