You are here

public static function MockService::getFactoryMethod in Service Container 7.2

Same name and namespace in other branches
  1. 7 tests/src/DependencyInjection/MockService.php \Drupal\Tests\service_container\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

tests/src/DependencyInjection/MockService.php, line 127
Contains \Drupal\Tests\service_container\DependencyInjection\MockService

Class

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

Namespace

Drupal\Tests\service_container\DependencyInjection

Code

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