|
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 |
|
@@ -516,7 +517,7 @@ protected function loadFile($file)
|
516 | 517 | }
|
517 | 518 |
|
518 | 519 | try {
|
519 |
| - $configuration = $this->yamlParser->parse(file_get_contents($file), Yaml::PARSE_CONSTANT); |
| 520 | + $configuration = $this->yamlParser->parse(file_get_contents($file), Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS); |
520 | 521 | } catch (ParseException $e) {
|
521 | 522 | throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
|
522 | 523 | }
|
@@ -567,42 +568,42 @@ private function validate($content, $file)
|
567 | 568 | /**
|
568 | 569 | * Resolves services.
|
569 | 570 | *
|
570 |
| - * @param string|array $value |
| 571 | + * @param mixed $value |
571 | 572 | *
|
572 |
| - * @return array|string|Reference |
| 573 | + * @return array|string|Reference|ArgumentInterface |
573 | 574 | */
|
574 | 575 | private function resolveServices($value)
|
575 | 576 | {
|
576 |
| - if (is_array($value)) { |
577 |
| - if (array_key_exists('=iterator', $value)) { |
578 |
| - if (1 !== count($value)) { |
579 |
| - throw new InvalidArgumentException('Arguments typed "=iterator" must have no sibling keys.'); |
580 |
| - } |
581 |
| - if (!is_array($value = $value['=iterator'])) { |
582 |
| - throw new InvalidArgumentException('Arguments typed "=iterator" must be arrays.'); |
583 |
| - } |
584 |
| - $value = new IteratorArgument(array_map(array($this, 'resolveServices'), $value)); |
585 |
| - } elseif (array_key_exists('=closure_proxy', $value)) { |
586 |
| - if (1 !== count($value)) { |
587 |
| - throw new InvalidArgumentException('Arguments typed "=closure_proxy" must have no sibling keys.'); |
588 |
| - } |
589 |
| - if (!is_array($value = $value['=closure_proxy']) || array(0, 1) !== array_keys($value)) { |
590 |
| - throw new InvalidArgumentException('Arguments typed "=closure_proxy" must be arrays of [@service, method].'); |
| 577 | + if ($value instanceof TaggedValue) { |
| 578 | + $argument = $value->getValue(); |
| 579 | + if ('iterator' === $value->getTag()) { |
| 580 | + if (!is_array($argument)) { |
| 581 | + throw new InvalidArgumentException('"!iterator" tag only accepts sequences.'); |
591 | 582 | }
|
592 |
| - if (!is_string($value[0]) || !is_string($value[1]) || 0 !== strpos($value[0], '@') || 0 === strpos($value[0], '@@')) { |
593 |
| - throw new InvalidArgumentException('Arguments typed "=closure_proxy" must be arrays of [@service, method].'); |
| 583 | + |
| 584 | + return new IteratorArgument(array_map(array($this, 'resolveServices'), $argument)); |
| 585 | + } |
| 586 | + if ('closure_proxy' === $value->getTag()) { |
| 587 | + 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], '@@')) { |
| 588 | + throw new InvalidArgumentException('"!closure_proxy" tagged values must be arrays of [@service, method].'); |
594 | 589 | }
|
595 |
| - if (0 === strpos($value[0], '@?')) { |
596 |
| - $value[0] = substr($value[0], 2); |
| 590 | + |
| 591 | + if (0 === strpos($argument[0], '@?')) { |
| 592 | + $argument[0] = substr($argument[0], 2); |
597 | 593 | $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
|
598 | 594 | } else {
|
599 |
| - $value[0] = substr($value[0], 1); |
| 595 | + $argument[0] = substr($argument[0], 1); |
600 | 596 | $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
601 | 597 | }
|
602 |
| - $value = new ClosureProxyArgument($value[0], $value[1], $invalidBehavior); |
603 |
| - } else { |
604 |
| - $value = array_map(array($this, 'resolveServices'), $value); |
| 598 | + |
| 599 | + return new ClosureProxyArgument($argument[0], $argument[1], $invalidBehavior); |
605 | 600 | }
|
| 601 | + |
| 602 | + throw new InvalidArgumentException(sprintf('Unsupported tag "!%s".', $value->getTag())); |
| 603 | + } |
| 604 | + |
| 605 | + if (is_array($value)) { |
| 606 | + $value = array_map(array($this, 'resolveServices'), $value); |
606 | 607 | } elseif (is_string($value) && 0 === strpos($value, '@=')) {
|
607 | 608 | return new Expression(substr($value, 2));
|
608 | 609 | } elseif (is_string($value) && 0 === strpos($value, '@')) {
|
|
0 commit comments