W3cubDocs

/Drupal 8

public static function Drupal::service

public static Drupal::service($id)

Retrieves a service from the container.

Use this method if the desired service is not one of those with a dedicated accessor method below. If it is listed below, those methods are preferred as they can return useful type hints.

Parameters

string $id: The ID of the service to retrieve.

Return value

mixed The specified service.

File

core/lib/Drupal.php, line 157
Contains \Drupal.

Class

Drupal
Static Service Container wrapper.

Code

public static function service($id) {
  return static::getContainer()->get($id);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal.php/function/Drupal::service/8.1.x