Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/simpletest/src/TestServiceProvider.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\simpletest; | 3 namespace Drupal\simpletest; |
4 | 4 |
5 use Drupal\Core\DependencyInjection\ContainerBuilder; | 5 use Drupal\KernelTests\TestServiceProvider as CoreTestServiceProvider; |
6 use Drupal\Core\DependencyInjection\ServiceModifierInterface; | |
7 use Drupal\Core\DependencyInjection\ServiceProviderInterface; | |
8 use Symfony\Component\DependencyInjection\Definition; | |
9 | 6 |
10 class TestServiceProvider implements ServiceProviderInterface, ServiceModifierInterface { | 7 /** |
11 | 8 * Provides special routing services for tests. |
12 /** | 9 * |
13 * @var \Drupal\simpletest\TestBase; | 10 * @deprecated in 8.6.0 for removal before Drupal 9.0.0. Use |
14 */ | 11 * Drupal\KernelTests\TestServiceProvider instead. |
15 public static $currentTest; | 12 * |
16 | 13 * @see https://www.drupal.org/node/2943146 |
17 /** | 14 */ |
18 * {@inheritdoc} | 15 class TestServiceProvider extends CoreTestServiceProvider { |
19 */ | |
20 public function register(ContainerBuilder $container) { | |
21 if (static::$currentTest && method_exists(static::$currentTest, 'containerBuild')) { | |
22 static::$currentTest->containerBuild($container); | |
23 } | |
24 } | |
25 | |
26 /** | |
27 * {@inheritdoc} | |
28 */ | |
29 public function alter(ContainerBuilder $container) { | |
30 if (static::$currentTest instanceof KernelTestBase) { | |
31 static::addRouteProvider($container); | |
32 } | |
33 } | |
34 | |
35 /** | |
36 * Add the on demand rebuild route provider service. | |
37 * | |
38 * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container | |
39 */ | |
40 public static function addRouteProvider(ContainerBuilder $container) { | |
41 foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) { | |
42 // While $container->get() does a recursive resolve, getDefinition() does | |
43 // not, so do it ourselves. | |
44 // @todo Make the code more readable in | |
45 // https://www.drupal.org/node/2911498. | |
46 for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id)) { | |
47 } | |
48 $definition = $container->getDefinition($id); | |
49 $definition->clearTag('needs_destruction'); | |
50 $container->setDefinition("simpletest.$original_id", $definition); | |
51 $container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class)); | |
52 } | |
53 } | |
54 | 16 |
55 } | 17 } |