ResolveClassPass.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\ChildDefinition;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  14. /**
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. class ResolveClassPass implements CompilerPassInterface
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function process(ContainerBuilder $container)
  23. {
  24. foreach ($container->getDefinitions() as $id => $definition) {
  25. if ($definition->isSynthetic() || null !== $definition->getClass()) {
  26. continue;
  27. }
  28. if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $id)) {
  29. if ($definition instanceof ChildDefinition && !class_exists($id)) {
  30. throw new InvalidArgumentException(sprintf('Service definition "%s" has a parent but no class, and its name looks like a FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.', $id));
  31. }
  32. $definition->setClass($id);
  33. }
  34. }
  35. }
  36. }