SetterInjection.php

Same filename and directory in other branches
  1. 9 core/modules/system/tests/modules/new_dependency_test/src/SetterInjection.php
  2. 10 core/modules/system/tests/modules/new_dependency_test/src/SetterInjection.php
  3. 11.x core/modules/system/tests/modules/new_dependency_test/src/SetterInjection.php

Namespace

Drupal\new_dependency_test

File

core/modules/system/tests/modules/new_dependency_test/src/SetterInjection.php

View source
<?php

namespace Drupal\new_dependency_test;

use Drupal\new_dependency_test_with_service\NewService;

/**
 * Generic service which uses setter injection.
 */
class SetterInjection {
  
  /**
   * The injected service.
   *
   * @var \Drupal\new_dependency_test_with_service\NewService
   */
  protected $service;
  
  /**
   * SetterInjection constructor.
   *
   * @param \Drupal\new_dependency_test_with_service\NewService $service
   *   The service of the new module.
   */
  public function setter(NewService $service) {
    $this->service = $service;
  }
  
  /**
   * Get the simple greeting from the service.
   *
   * @return string
   *   The greeting.
   */
  public function greet() {
    return $this->service
      ->greet();
  }

}

Classes

Title Deprecated Summary
SetterInjection Generic service which uses setter injection.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.