Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/dependency-injection/Compiler/CheckDefinitionValidityPass.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 | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
10 */ | 10 */ |
11 | 11 |
12 namespace Symfony\Component\DependencyInjection\Compiler; | 12 namespace Symfony\Component\DependencyInjection\Compiler; |
13 | 13 |
14 use Symfony\Component\DependencyInjection\ContainerBuilder; | 14 use Symfony\Component\DependencyInjection\ContainerBuilder; |
15 use Symfony\Component\DependencyInjection\Exception\EnvParameterException; | |
15 use Symfony\Component\DependencyInjection\Exception\RuntimeException; | 16 use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
16 | 17 |
17 /** | 18 /** |
18 * This pass validates each definition individually only taking the information | 19 * This pass validates each definition individually only taking the information |
19 * into account which is contained in the definition itself. | 20 * into account which is contained in the definition itself. |
29 class CheckDefinitionValidityPass implements CompilerPassInterface | 30 class CheckDefinitionValidityPass implements CompilerPassInterface |
30 { | 31 { |
31 /** | 32 /** |
32 * Processes the ContainerBuilder to validate the Definition. | 33 * Processes the ContainerBuilder to validate the Definition. |
33 * | 34 * |
34 * @param ContainerBuilder $container | |
35 * | |
36 * @throws RuntimeException When the Definition is invalid | 35 * @throws RuntimeException When the Definition is invalid |
37 */ | 36 */ |
38 public function process(ContainerBuilder $container) | 37 public function process(ContainerBuilder $container) |
39 { | 38 { |
40 foreach ($container->getDefinitions() as $id => $definition) { | 39 foreach ($container->getDefinitions() as $id => $definition) { |
41 // synthetic service is public | 40 // synthetic service is public |
42 if ($definition->isSynthetic() && !$definition->isPublic()) { | 41 if ($definition->isSynthetic() && !($definition->isPublic() || $definition->isPrivate())) { |
43 throw new RuntimeException(sprintf('A synthetic service ("%s") must be public.', $id)); | 42 throw new RuntimeException(sprintf('A synthetic service ("%s") must be public.', $id)); |
44 } | 43 } |
45 | 44 |
46 // non-synthetic, non-abstract service has class | 45 // non-synthetic, non-abstract service has class |
47 if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) { | 46 if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) { |
48 if ($definition->getFactory()) { | 47 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)); | 48 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)); |
49 } | |
50 if (class_exists($id) || interface_exists($id, false)) { | |
51 throw new RuntimeException(sprintf( | |
52 'The definition for "%s" has no class attribute, and appears to reference a ' | |
53 .'class or interface in the global namespace. Leaving out the "class" attribute ' | |
54 .'is only allowed for namespaced classes. Please specify the class attribute ' | |
55 .'explicitly to get rid of this error.', | |
56 $id | |
57 )); | |
50 } | 58 } |
51 | 59 |
52 throw new RuntimeException(sprintf( | 60 throw new RuntimeException(sprintf( |
53 'The definition for "%s" has no class. If you intend to inject ' | 61 'The definition for "%s" has no class. If you intend to inject ' |
54 .'this service dynamically at runtime, please mark it as synthetic=true. ' | 62 .'this service dynamically at runtime, please mark it as synthetic=true. ' |
66 throw new RuntimeException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s".', $id, $name, $attribute)); | 74 throw new RuntimeException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s".', $id, $name, $attribute)); |
67 } | 75 } |
68 } | 76 } |
69 } | 77 } |
70 } | 78 } |
79 | |
80 if ($definition->isPublic() && !$definition->isPrivate()) { | |
81 $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs); | |
82 if (null !== $usedEnvs) { | |
83 throw new EnvParameterException(array($resolvedId), null, 'A service name ("%s") cannot contain dynamic values.'); | |
84 } | |
85 } | |
86 } | |
87 | |
88 foreach ($container->getAliases() as $id => $alias) { | |
89 if ($alias->isPublic() && !$alias->isPrivate()) { | |
90 $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs); | |
91 if (null !== $usedEnvs) { | |
92 throw new EnvParameterException(array($resolvedId), null, 'An alias name ("%s") cannot contain dynamic values.'); | |
93 } | |
94 } | |
71 } | 95 } |
72 } | 96 } |
73 } | 97 } |