[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Compiler/ -> CheckDefinitionValidityPass.php (source)

   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\EnvParameterException;
  16  use Symfony\Component\DependencyInjection\Exception\RuntimeException;
  17  
  18  /**
  19   * This pass validates each definition individually only taking the information
  20   * into account which is contained in the definition itself.
  21   *
  22   * Later passes can rely on the following, and specifically do not need to
  23   * perform these checks themselves:
  24   *
  25   * - non synthetic, non abstract services always have a class set
  26   * - synthetic services are always public
  27   *
  28   * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  29   */
  30  class CheckDefinitionValidityPass implements CompilerPassInterface
  31  {
  32      /**
  33       * Processes the ContainerBuilder to validate the Definition.
  34       *
  35       * @throws RuntimeException When the Definition is invalid
  36       */
  37      public function process(ContainerBuilder $container)
  38      {
  39          foreach ($container->getDefinitions() as $id => $definition) {
  40              // synthetic service is public
  41              if ($definition->isSynthetic() && !($definition->isPublic() || $definition->isPrivate())) {
  42                  throw new RuntimeException(sprintf('A synthetic service ("%s") must be public.', $id));
  43              }
  44  
  45              // non-synthetic, non-abstract service has class
  46              if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) {
  47                  if ($definition->getFactory()) {
  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                      if (0 === strpos($id, '\\') && 1 < substr_count($id, '\\')) {
  52                          throw new RuntimeException(sprintf('The definition for "%s" has no class attribute, and appears to reference a class or interface. Please specify the class attribute explicitly or remove the leading backslash by renaming the service to "%s" to get rid of this error.', $id, substr($id, 1)));
  53                      }
  54  
  55                      throw new RuntimeException(sprintf('The definition for "%s" has no class attribute, and appears to reference a class or interface in the global namespace. Leaving out the "class" attribute is only allowed for namespaced classes. Please specify the class attribute explicitly to get rid of this error.', $id));
  56                  }
  57  
  58                  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));
  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              if ($definition->isPublic() && !$definition->isPrivate()) {
  73                  $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
  74                  if (null !== $usedEnvs) {
  75                      throw new EnvParameterException([$resolvedId], null, 'A service name ("%s") cannot contain dynamic values.');
  76                  }
  77              }
  78          }
  79  
  80          foreach ($container->getAliases() as $id => $alias) {
  81              if ($alias->isPublic() && !$alias->isPrivate()) {
  82                  $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
  83                  if (null !== $usedEnvs) {
  84                      throw new EnvParameterException([$resolvedId], null, 'An alias name ("%s") cannot contain dynamic values.');
  85                  }
  86              }
  87          }
  88      }
  89  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1