Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54beb0b

Browse files
committed
Fix comments
1 parent 1a00dc3 commit 54beb0b

File tree

8 files changed

+65
-159
lines changed

8 files changed

+65
-159
lines changed

UPGRADE-3.3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ TwigBridge
5050

5151
* The `TwigRendererEngine::setEnvironment()` method has been deprecated and will be removed
5252
in 4.0. Pass the Twig Environment as second argument of the constructor instead.
53+
54+
Yaml
55+
----
56+
57+
* Constructor arguments `$offset`, `$totalNumberOfLines` and
58+
`$skippedLineNumbers` of `Parser` are deprecated and will be
59+
removed in 4.0

UPGRADE-4.0.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Serializer
210210
* The ability to pass a Doctrine `Cache` instance to the `ClassMetadataFactory`
211211
class has been removed. You should use the `CacheClassMetadataFactory` class
212212
instead.
213-
213+
214214
* Not defining the 6th argument `$format = null` of the
215215
`AbstractNormalizer::instantiateObject()` method when overriding it is not
216216
supported anymore.
@@ -288,9 +288,9 @@ Validator
288288
// ...
289289
}
290290
```
291-
291+
292292
* The default value of the strict option of the `Choice` Constraint has been
293-
changed to `true` as of 4.0. If you need the the previous behaviour ensure to
293+
changed to `true` as of 4.0. If you need the the previous behaviour ensure to
294294
set the option to `false`.
295295

296296
Yaml
@@ -384,3 +384,6 @@ Yaml
384384
the `!php/object` tag.
385385

386386
* Duplicate mapping keys lead to a `ParseException`.
387+
388+
* Constructor arguments `$offset`, `$totalNumberOfLines` and
389+
`$skippedLineNumbers` of `Parser` were removed.

src/Symfony/Component/Yaml/Exception/UnsupportedTagException.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Symfony/Component/Yaml/Inline.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Yaml;
1313

1414
use Symfony\Component\Yaml\Exception\ParseException;
15-
use Symfony\Component\Yaml\Exception\UnsupportedTagException;
1615
use Symfony\Component\Yaml\Exception\DumpException;
1716

1817
/**
@@ -27,7 +26,7 @@ class Inline
2726
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\']*(?:\'\'[^\']*)*)\')';
2827

2928
public static $parsedLineNumber;
30-
public static $tagResolver;
29+
public static $tags = array();
3130

3231
private static $exceptionOnInvalidType = false;
3332
private static $objectSupport = false;
@@ -663,16 +662,14 @@ private static function evaluateScalar($scalar, $flags, $references = array())
663662
}
664663
}
665664

666-
if (null !== self::$tagResolver && '!' === $scalar[0]) {
665+
if (0 !== count(self::$tags) && '!' === $scalar[0]) {
667666
$tagLength = strcspn($scalar, " \t", 1);
668667
$tag = substr($scalar, 1, $tagLength);
669-
$i = 0;
670-
$scalar = self::parseScalar(ltrim(substr($scalar, $tagLength)), $flags, null, array('"', "'"), $i, false, $references);
668+
if (isset(self::$tags[$tag])) {
669+
$i = 0;
670+
$scalar = self::parseScalar(ltrim(substr($scalar, $tagLength)), $flags, null, array('"', "'"), $i, false, $references);
671671

672-
try {
673-
return self::$tagResolver->resolve($scalar, $tag);
674-
} catch (UnsupportedTagException $e) {
675-
// Ignored for bc
672+
return self::$tags[$tag]->construct($scalar);
676673
}
677674
}
678675

src/Symfony/Component/Yaml/Parser.php

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
namespace Symfony\Component\Yaml;
1313

1414
use Symfony\Component\Yaml\Exception\ParseException;
15-
use Symfony\Component\Yaml\Exception\UnsupportedTagException;
1615
use Symfony\Component\Yaml\Tag\TagInterface;
17-
use Symfony\Component\Yaml\Tag\TagResolver;
1816

1917
/**
2018
* Parser parses YAML strings to convert them to PHP arrays.
@@ -34,30 +32,35 @@ class Parser
3432
private $refs = array();
3533
private $skippedLineNumbers = array();
3634
private $locallySkippedLineNumbers = array();
37-
private $tagResolver;
35+
private $tags = array();
3836

3937
/**
40-
* Constructor.
41-
*
42-
* @param int $offset The offset of YAML document (used for line numbers in error messages)
43-
* @param int|null $totalNumberOfLines The overall number of lines being parsed
44-
* @param int[] $skippedLineNumbers Number of comment lines that have been skipped by the parser
38+
* @param array $tags array of {@link TagInterface} with their name as key
4539
*/
46-
public function __construct($offset = 0, $totalNumberOfLines = null, array $skippedLineNumbers = array())
40+
public function __construct($tags = array())
4741
{
48-
$this->offset = $offset;
49-
$this->totalNumberOfLines = $totalNumberOfLines;
50-
$this->skippedLineNumbers = $skippedLineNumbers;
51-
$this->tagResolver = new TagResolver();
52-
}
42+
if (!is_array($tags) || func_num_args() > 1) {
43+
@trigger_error(sprintf('Constructor arguments $offset, $totalNumberOfLines, $skippedLineNumbers of %s are deprecated and will be removed in 4.0', Parser::class), E_USER_DEPRECATED);
5344

54-
/**
55-
* @param TagInterface $tag
56-
* @param int $priority
57-
*/
58-
public function addTag(TagInterface $tag, $priority = 0)
59-
{
60-
$this->tagResolver->addTag($tag, $priority);
45+
if (!is_array($tags)) {
46+
$this->offset = $tags;
47+
$tags = array();
48+
}
49+
if (func_num_args() > 1) {
50+
$this->totalNumberOfLines = func_get_arg(1);
51+
}
52+
if (func_num_args() > 2) {
53+
$this->skippedLineNumbers = func_get_arg(2);
54+
}
55+
}
56+
57+
foreach ($tags as $tagName => $tag) {
58+
if (0 === strpos($tagName, 'tag:yaml.org,2002:')) {
59+
$tagName = '!'.substr($tagName, 18);
60+
}
61+
62+
$this->tags[$tagName] = $tag;
63+
}
6164
}
6265

6366
/**
@@ -115,11 +118,11 @@ public function parse($value, $flags = 0)
115118
mb_internal_encoding('UTF-8');
116119
}
117120

118-
Inline::$tagResolver = $this->tagResolver;
121+
Inline::$tags = $this->tags;
119122
try {
120123
return $this->doParse($value, $flags);
121124
} finally {
122-
Inline::$tagResolver = null;
125+
Inline::$tags = array();
123126
}
124127
}
125128

@@ -408,9 +411,14 @@ private function parseBlock($offset, $yaml, $flags)
408411
$skippedLineNumbers[] = $lineNumber;
409412
}
410413

411-
$parser = new self($offset, $this->totalNumberOfLines, $skippedLineNumbers);
414+
$parser = new self();
415+
$parser->offset = $offset;
416+
$parser->totalNumberOfLines = $this->totalNumberOfLines;
417+
$parser->skippedLineNumbers = $skippedLineNumbers;
412418
$parser->refs = &$this->refs;
413-
$parser->tagResolver = $this->tagResolver;
419+
420+
// Bypass the prefix removal
421+
$parser->tags = $this->tags;
414422

415423
return $parser->parse($yaml, $flags);
416424
}
@@ -630,11 +638,8 @@ private function parseValue($value, $flags, $context)
630638
}
631639

632640
$tag = substr($matches['tag'], 1);
633-
634-
try {
635-
return $this->tagResolver->resolve($data, $tag);
636-
} catch (UnsupportedTagException $e) {
637-
// ignored for bc
641+
if (isset($this->tags[$tag])) {
642+
return $this->tags[$tag]->construct($data);
638643
}
639644
}
640645

src/Symfony/Component/Yaml/Tag/TagInterface.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,8 @@ interface TagInterface
1818
{
1919
/**
2020
* @param mixed $value
21-
* @param string $tag
2221
*
2322
* @return mixed
2423
*/
25-
public function construct($value, $tag);
26-
27-
/**
28-
* @param mixed $value
29-
* @param string $tag
30-
*
31-
* @return bool
32-
*/
33-
public function supports($value, $tag);
24+
public function construct($value);
3425
}

src/Symfony/Component/Yaml/Tag/TagResolver.php

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,9 +1495,16 @@ public function testParseMultiLineMappingValue()
14951495

14961496
public function testCustomTagSupport()
14971497
{
1498-
$this->parser->addTag(new FooTag());
1498+
$parser = new Parser(array(
1499+
'foo' => new FooTag(),
1500+
'tag:yaml.org,2002:quz' => new FooTag(),
1501+
));
14991502

1500-
$this->assertSame('bar', $this->parser->parse('!foo'));
1503+
$yaml = <<<YAML
1504+
- !foo
1505+
- !!quz bar
1506+
YAML;
1507+
$this->assertSame(array('bar', 'bar'), $parser->parse($yaml));
15011508
}
15021509
}
15031510

@@ -1511,16 +1518,8 @@ class FooTag implements TagInterface
15111518
/**
15121519
* {@inheritdoc}
15131520
*/
1514-
public function construct($value, $tag)
1521+
public function construct($value)
15151522
{
15161523
return 'bar';
15171524
}
1518-
1519-
/**
1520-
* {@inheritdoc}
1521-
*/
1522-
public function supports($value, $tag)
1523-
{
1524-
return 'foo' === $tag;
1525-
}
15261525
}

0 commit comments

Comments
 (0)