CheckDefinitionValidityPass.php in Zircon Profile 8
File
vendor/symfony/dependency-injection/Compiler/CheckDefinitionValidityPass.php
View source
<?php
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
class CheckDefinitionValidityPass implements CompilerPassInterface {
public function process(ContainerBuilder $container) {
foreach ($container
->getDefinitions() as $id => $definition) {
if ($definition
->isSynthetic() && !$definition
->isPublic()) {
throw new RuntimeException(sprintf('A synthetic service ("%s") must be public.', $id));
}
if ($definition
->isSynthetic() && ContainerInterface::SCOPE_PROTOTYPE === $definition
->getScope()) {
throw new RuntimeException(sprintf('A synthetic service ("%s") cannot be of scope "prototype".', $id));
}
if ($definition
->getFactory() && ($definition
->getFactoryClass(false) || $definition
->getFactoryService(false) || $definition
->getFactoryMethod(false))) {
throw new RuntimeException(sprintf('A service ("%s") can use either the old or the new factory syntax, not both.', $id));
}
if (!$definition
->isAbstract() && !$definition
->isSynthetic() && !$definition
->getClass()) {
if ($definition
->getFactory() || $definition
->getFactoryClass(false) || $definition
->getFactoryService(false)) {
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));
}
throw new RuntimeException(sprintf('The definition for "%s" has no class. If you intend to inject ' . 'this service dynamically at runtime, please mark it as synthetic=true. ' . 'If this is an abstract definition solely used by child definitions, ' . 'please add abstract=true, otherwise specify a class to get rid of this error.', $id));
}
foreach ($definition
->getTags() as $name => $tags) {
foreach ($tags as $attributes) {
foreach ($attributes as $attribute => $value) {
if (!is_scalar($value) && null !== $value) {
throw new RuntimeException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s".', $id, $name, $attribute));
}
}
}
}
}
}
}
Classes
Name |
Description |
CheckDefinitionValidityPass |
This pass validates each definition individually only taking the information
into account which is contained in the definition itself. |