annotate vendor/symfony/dependency-injection/Compiler/CheckArgumentsValidityPass.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@14 1 <?php
Chris@14 2
Chris@14 3 /*
Chris@14 4 * This file is part of the Symfony package.
Chris@14 5 *
Chris@14 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@14 7 *
Chris@14 8 * For the full copyright and license information, please view the LICENSE
Chris@14 9 * file that was distributed with this source code.
Chris@14 10 */
Chris@14 11
Chris@14 12 namespace Symfony\Component\DependencyInjection\Compiler;
Chris@14 13
Chris@14 14 use Symfony\Component\DependencyInjection\Definition;
Chris@14 15 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
Chris@14 16
Chris@14 17 /**
Chris@14 18 * Checks if arguments of methods are properly configured.
Chris@14 19 *
Chris@14 20 * @author Kévin Dunglas <dunglas@gmail.com>
Chris@14 21 * @author Nicolas Grekas <p@tchwork.com>
Chris@14 22 */
Chris@14 23 class CheckArgumentsValidityPass extends AbstractRecursivePass
Chris@14 24 {
Chris@14 25 private $throwExceptions;
Chris@14 26
Chris@14 27 public function __construct($throwExceptions = true)
Chris@14 28 {
Chris@14 29 $this->throwExceptions = $throwExceptions;
Chris@14 30 }
Chris@14 31
Chris@14 32 /**
Chris@14 33 * {@inheritdoc}
Chris@14 34 */
Chris@14 35 protected function processValue($value, $isRoot = false)
Chris@14 36 {
Chris@14 37 if (!$value instanceof Definition) {
Chris@14 38 return parent::processValue($value, $isRoot);
Chris@14 39 }
Chris@14 40
Chris@14 41 $i = 0;
Chris@14 42 foreach ($value->getArguments() as $k => $v) {
Chris@14 43 if ($k !== $i++) {
Chris@17 44 if (!\is_int($k)) {
Chris@14 45 $msg = sprintf('Invalid constructor argument for service "%s": integer expected but found string "%s". Check your service definition.', $this->currentId, $k);
Chris@14 46 $value->addError($msg);
Chris@14 47 if ($this->throwExceptions) {
Chris@14 48 throw new RuntimeException($msg);
Chris@14 49 }
Chris@14 50
Chris@14 51 break;
Chris@14 52 }
Chris@14 53
Chris@14 54 $msg = sprintf('Invalid constructor argument %d for service "%s": argument %d must be defined before. Check your service definition.', 1 + $k, $this->currentId, $i);
Chris@14 55 $value->addError($msg);
Chris@14 56 if ($this->throwExceptions) {
Chris@14 57 throw new RuntimeException($msg);
Chris@14 58 }
Chris@14 59 }
Chris@14 60 }
Chris@14 61
Chris@14 62 foreach ($value->getMethodCalls() as $methodCall) {
Chris@14 63 $i = 0;
Chris@14 64 foreach ($methodCall[1] as $k => $v) {
Chris@14 65 if ($k !== $i++) {
Chris@17 66 if (!\is_int($k)) {
Chris@14 67 $msg = sprintf('Invalid argument for method call "%s" of service "%s": integer expected but found string "%s". Check your service definition.', $methodCall[0], $this->currentId, $k);
Chris@14 68 $value->addError($msg);
Chris@14 69 if ($this->throwExceptions) {
Chris@14 70 throw new RuntimeException($msg);
Chris@14 71 }
Chris@14 72
Chris@14 73 break;
Chris@14 74 }
Chris@14 75
Chris@14 76 $msg = sprintf('Invalid argument %d for method call "%s" of service "%s": argument %d must be defined before. Check your service definition.', 1 + $k, $methodCall[0], $this->currentId, $i);
Chris@14 77 $value->addError($msg);
Chris@14 78 if ($this->throwExceptions) {
Chris@14 79 throw new RuntimeException($msg);
Chris@14 80 }
Chris@14 81 }
Chris@14 82 }
Chris@14 83 }
Chris@14 84 }
Chris@14 85 }