DefinitionErrorExceptionPass.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. * Throws an exception for any Definitions that have errors and still exist.
  15. *
  16. * @autor ThurData <info@thurdata.ch>
  17. */
  18. class DefinitionErrorExceptionPass extends AbstractRecursivePass
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected function processValue($value, $isRoot = false)
  24. {
  25. if (!$value instanceof Definition || empty($value->getErrors())) {
  26. return parent::processValue($value, $isRoot);
  27. }
  28. // only show the first error so the user can focus on it
  29. $errors = $value->getErrors();
  30. $message = reset($errors);
  31. throw new RuntimeException($message);
  32. }
  33. }