4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Compiler;
14 use Symfony\Component\DependencyInjection\Definition;
15 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
18 * Checks if arguments of methods are properly configured.
20 * @author Kévin Dunglas <dunglas@gmail.com>
21 * @author Nicolas Grekas <p@tchwork.com>
23 class CheckArgumentsValidityPass extends AbstractRecursivePass
25 private $throwExceptions;
27 public function __construct($throwExceptions = true)
29 $this->throwExceptions = $throwExceptions;
35 protected function processValue($value, $isRoot = false)
37 if (!$value instanceof Definition) {
38 return parent::processValue($value, $isRoot);
42 foreach ($value->getArguments() as $k => $v) {
45 $msg = sprintf('Invalid constructor argument for service "%s": integer expected but found string "%s". Check your service definition.', $this->currentId, $k);
46 $value->addError($msg);
47 if ($this->throwExceptions) {
48 throw new RuntimeException($msg);
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);
55 $value->addError($msg);
56 if ($this->throwExceptions) {
57 throw new RuntimeException($msg);
62 foreach ($value->getMethodCalls() as $methodCall) {
64 foreach ($methodCall[1] as $k => $v) {
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);
68 $value->addError($msg);
69 if ($this->throwExceptions) {
70 throw new RuntimeException($msg);
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);
77 $value->addError($msg);
78 if ($this->throwExceptions) {
79 throw new RuntimeException($msg);