Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/dependency-injection/Compiler/CheckDefinitionValidityPass.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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\DependencyInjection\Compiler; | |
13 | |
14 use Symfony\Component\DependencyInjection\ContainerBuilder; | |
15 use Symfony\Component\DependencyInjection\Exception\RuntimeException; | |
16 | |
17 /** | |
18 * This pass validates each definition individually only taking the information | |
19 * into account which is contained in the definition itself. | |
20 * | |
21 * Later passes can rely on the following, and specifically do not need to | |
22 * perform these checks themselves: | |
23 * | |
24 * - non synthetic, non abstract services always have a class set | |
25 * - synthetic services are always public | |
26 * | |
27 * @author Johannes M. Schmitt <schmittjoh@gmail.com> | |
28 */ | |
29 class CheckDefinitionValidityPass implements CompilerPassInterface | |
30 { | |
31 /** | |
32 * Processes the ContainerBuilder to validate the Definition. | |
33 * | |
34 * @param ContainerBuilder $container | |
35 * | |
36 * @throws RuntimeException When the Definition is invalid | |
37 */ | |
38 public function process(ContainerBuilder $container) | |
39 { | |
40 foreach ($container->getDefinitions() as $id => $definition) { | |
41 // synthetic service is public | |
42 if ($definition->isSynthetic() && !$definition->isPublic()) { | |
43 throw new RuntimeException(sprintf('A synthetic service ("%s") must be public.', $id)); | |
44 } | |
45 | |
46 // non-synthetic, non-abstract service has class | |
47 if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) { | |
48 if ($definition->getFactory()) { | |
49 throw new RuntimeException(sprintf('Please add the class to service "%s" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.', $id)); | |
50 } | |
51 | |
52 throw new RuntimeException(sprintf( | |
53 'The definition for "%s" has no class. If you intend to inject ' | |
54 .'this service dynamically at runtime, please mark it as synthetic=true. ' | |
55 .'If this is an abstract definition solely used by child definitions, ' | |
56 .'please add abstract=true, otherwise specify a class to get rid of this error.', | |
57 $id | |
58 )); | |
59 } | |
60 | |
61 // tag attribute values must be scalars | |
62 foreach ($definition->getTags() as $name => $tags) { | |
63 foreach ($tags as $attributes) { | |
64 foreach ($attributes as $attribute => $value) { | |
65 if (!is_scalar($value) && null !== $value) { | |
66 throw new RuntimeException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s".', $id, $name, $attribute)); | |
67 } | |
68 } | |
69 } | |
70 } | |
71 } | |
72 } | |
73 } |