|
23 | 23 | use Symfony\Component\Config\Resource\FileResource;
|
24 | 24 | use Symfony\Component\Yaml\Exception\ParseException;
|
25 | 25 | use Symfony\Component\Yaml\Parser as YamlParser;
|
| 26 | +use Symfony\Component\Yaml\Tag\TaggedValue; |
26 | 27 | use Symfony\Component\Yaml\Yaml;
|
27 | 28 | use Symfony\Component\ExpressionLanguage\Expression;
|
28 | 29 |
|
@@ -506,7 +507,7 @@ protected function loadFile($file)
|
506 | 507 | }
|
507 | 508 |
|
508 | 509 | try {
|
509 |
| - $configuration = $this->yamlParser->parse(file_get_contents($file), Yaml::PARSE_CONSTANT); |
| 510 | + $configuration = $this->yamlParser->parse(file_get_contents($file), Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS); |
510 | 511 | } catch (ParseException $e) {
|
511 | 512 | throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
|
512 | 513 | }
|
@@ -557,42 +558,42 @@ private function validate($content, $file)
|
557 | 558 | /**
|
558 | 559 | * Resolves services.
|
559 | 560 | *
|
560 |
| - * @param string|array $value |
| 561 | + * @param mixed $value |
561 | 562 | *
|
562 |
| - * @return array|string|Reference |
| 563 | + * @return array|string|Reference|ArgumentInterface |
563 | 564 | */
|
564 | 565 | private function resolveServices($value)
|
565 | 566 | {
|
566 |
| - if (is_array($value)) { |
567 |
| - if (array_key_exists('=iterator', $value)) { |
568 |
| - if (1 !== count($value)) { |
569 |
| - throw new InvalidArgumentException('Arguments typed "=iterator" must have no sibling keys.'); |
570 |
| - } |
571 |
| - if (!is_array($value = $value['=iterator'])) { |
572 |
| - throw new InvalidArgumentException('Arguments typed "=iterator" must be arrays.'); |
573 |
| - } |
574 |
| - $value = new IteratorArgument(array_map(array($this, 'resolveServices'), $value)); |
575 |
| - } elseif (array_key_exists('=closure_proxy', $value)) { |
576 |
| - if (1 !== count($value)) { |
577 |
| - throw new InvalidArgumentException('Arguments typed "=closure_proxy" must have no sibling keys.'); |
578 |
| - } |
579 |
| - if (!is_array($value = $value['=closure_proxy']) || array(0, 1) !== array_keys($value)) { |
580 |
| - throw new InvalidArgumentException('Arguments typed "=closure_proxy" must be arrays of [@service, method].'); |
| 567 | + if ($value instanceof TaggedValue) { |
| 568 | + $argument = $value->getValue(); |
| 569 | + if ('iterator' === $value->getTag()) { |
| 570 | + if (!is_array($argument)) { |
| 571 | + throw new InvalidArgumentException('"!iterator" tag only accepts sequences.'); |
581 | 572 | }
|
582 |
| - if (!is_string($value[0]) || !is_string($value[1]) || 0 !== strpos($value[0], '@') || 0 === strpos($value[0], '@@')) { |
583 |
| - throw new InvalidArgumentException('Arguments typed "=closure_proxy" must be arrays of [@service, method].'); |
| 573 | + |
| 574 | + return new IteratorArgument(array_map(array($this, 'resolveServices'), $argument)); |
| 575 | + } |
| 576 | + if ('closure_proxy' === $value->getTag()) { |
| 577 | + if (!is_array($argument) || array(0, 1) !== array_keys($argument) || !is_string($argument[0]) || !is_string($argument[1]) || 0 !== strpos($argument[0], '@') || 0 === strpos($argument[0], '@@')) { |
| 578 | + throw new InvalidArgumentException('"!closure_proxy" tagged values must be arrays of [@service, method].'); |
584 | 579 | }
|
585 |
| - if (0 === strpos($value[0], '@?')) { |
586 |
| - $value[0] = substr($value[0], 2); |
| 580 | + |
| 581 | + if (0 === strpos($argument[0], '@?')) { |
| 582 | + $argument[0] = substr($argument[0], 2); |
587 | 583 | $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
|
588 | 584 | } else {
|
589 |
| - $value[0] = substr($value[0], 1); |
| 585 | + $argument[0] = substr($argument[0], 1); |
590 | 586 | $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
591 | 587 | }
|
592 |
| - $value = new ClosureProxyArgument($value[0], $value[1], $invalidBehavior); |
593 |
| - } else { |
594 |
| - $value = array_map(array($this, 'resolveServices'), $value); |
| 588 | + |
| 589 | + return new ClosureProxyArgument($argument[0], $argument[1], $invalidBehavior); |
595 | 590 | }
|
| 591 | + |
| 592 | + throw new InvalidArgumentException(sprintf('Unsupported tag "!%s".', $value->getTag())); |
| 593 | + } |
| 594 | + |
| 595 | + if (is_array($value)) { |
| 596 | + $value = array_map(array($this, 'resolveServices'), $value); |
596 | 597 | } elseif (is_string($value) && 0 === strpos($value, '@=')) {
|
597 | 598 | return new Expression(substr($value, 2));
|
598 | 599 | } elseif (is_string($value) && 0 === strpos($value, '@')) {
|
|
0 commit comments