ResolveClassPass.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\ChildDefinition;
  13. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  14. /**
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. class ResolveClassPass implements CompilerPassInterface
  18. {
  19. private $changes = array();
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function process(ContainerBuilder $container)
  24. {
  25. foreach ($container->getDefinitions() as $id => $definition) {
  26. if ($definition->isSynthetic() || null !== $definition->getClass()) {
  27. continue;
  28. }
  29. 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)) {
  30. if ($definition instanceof ChildDefinition && !class_exists($id)) {
  31. 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));
  32. }
  33. $this->changes[strtolower($id)] = $id;
  34. $definition->setClass($id);
  35. }
  36. }
  37. }
  38. /**
  39. * @internal
  40. *
  41. * @deprecated since 3.3, to be removed in 4.0.
  42. */
  43. public function getChanges()
  44. {
  45. $changes = $this->changes;
  46. $this->changes = array();
  47. return $changes;
  48. }
  49. }