Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/serializer/DependencyInjection/SerializerPass.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony package. | |
5 * | |
6 * (c) Fabien Potencier <fabien@symfony.com> | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Symfony\Component\Serializer\DependencyInjection; | |
13 | |
14 use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; | |
15 use Symfony\Component\DependencyInjection\ContainerBuilder; | |
16 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | |
17 use Symfony\Component\DependencyInjection\Exception\RuntimeException; | |
18 | |
19 /** | |
20 * Adds all services with the tags "serializer.encoder" and "serializer.normalizer" as | |
21 * encoders and normalizers to the "serializer" service. | |
22 * | |
23 * @author Javier Lopez <f12loalf@gmail.com> | |
24 * @author Robin Chalas <robin.chalas@gmail.com> | |
25 */ | |
26 class SerializerPass implements CompilerPassInterface | |
27 { | |
28 use PriorityTaggedServiceTrait; | |
29 | |
30 private $serializerService; | |
31 private $normalizerTag; | |
32 private $encoderTag; | |
33 | |
34 public function __construct($serializerService = 'serializer', $normalizerTag = 'serializer.normalizer', $encoderTag = 'serializer.encoder') | |
35 { | |
36 $this->serializerService = $serializerService; | |
37 $this->normalizerTag = $normalizerTag; | |
38 $this->encoderTag = $encoderTag; | |
39 } | |
40 | |
41 public function process(ContainerBuilder $container) | |
42 { | |
43 if (!$container->hasDefinition($this->serializerService)) { | |
44 return; | |
45 } | |
46 | |
47 if (!$normalizers = $this->findAndSortTaggedServices($this->normalizerTag, $container)) { | |
48 throw new RuntimeException(sprintf('You must tag at least one service as "%s" to use the "%s" service.', $this->normalizerTag, $this->serializerService)); | |
49 } | |
50 | |
51 $serializerDefinition = $container->getDefinition($this->serializerService); | |
52 $serializerDefinition->replaceArgument(0, $normalizers); | |
53 | |
54 if (!$encoders = $this->findAndSortTaggedServices($this->encoderTag, $container)) { | |
55 throw new RuntimeException(sprintf('You must tag at least one service as "%s" to use the "%s" service.', $this->encoderTag, $this->serializerService)); | |
56 } | |
57 | |
58 $serializerDefinition->replaceArgument(1, $encoders); | |
59 } | |
60 } |