function MockService::getFactoryMethod

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\MockService::getFactoryMethod()
  2. 10 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\MockService::getFactoryMethod()
  3. 11.x core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\MockService::getFactoryMethod()

Provides a factory method to get a service.

Parameters

string $class: The class name of the class to instantiate

array $arguments: (optional) Arguments to pass to the new class.

Return value

object The instantiated service object.

File

core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php, line 1200

Class

MockService
Helper class to test Container::get() method.

Namespace

Drupal\Tests\Component\DependencyInjection

Code

public static function getFactoryMethod($class, $arguments = []) {
    $r = new \ReflectionClass($class);
    $service = $r->getConstructor() === NULL ? $r->newInstance() : $r->newInstanceArgs($arguments);
    return $service;
}

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