ResolveFactoryClassPass.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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\Definition;
  12. use Symfony\Component\DependencyInjection\Exception\RuntimeException;
  13. /**
  14. * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
  15. */
  16. class ResolveFactoryClassPass extends AbstractRecursivePass
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. protected function processValue($value, bool $isRoot = false)
  22. {
  23. if ($value instanceof Definition && \is_array($factory = $value->getFactory()) && null === $factory[0]) {
  24. if (null === $class = $value->getClass()) {
  25. throw new RuntimeException(sprintf('The "%s" service is defined to be created by a factory, but is missing the factory class. Did you forget to define the factory or service class?', $this->currentId));
  26. }
  27. $factory[0] = $class;
  28. $value->setFactory($factory);
  29. }
  30. return parent::processValue($value, $isRoot);
  31. }
  32. }