8000 Merge branch '2.7' into 2.8 · symfony/symfony@b89ed60 · GitHub
[go: up one dir, main page]

Skip to content

Commit b89ed60

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: don't keep internal state between parser runs Add \Traversable typehint to phpdoc [ExpressionLanguage] Avoid dependency on ctype [Debug] Fix php notice
2 parents 1272be6 + 34655e6 commit b89ed60

File tree

5 files changed

+61
-20
lines changed

5 files changed

+61
-20
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function loadClass($class)
186186

187187
$exists = class_exists($class, false) || interface_exists($class, false) || (function_exists('trait_exists') && trait_exists($class, false));
188188

189-
if ('\\' === $class[0]) {
189+
if ($class && '\\' === $class[0]) {
190190
$class = substr($class, 1);
191191
}
192192

src/Symfony/Component/ExpressionLanguage/Lexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function tokenize($expression)
4545
if (preg_match('/[0-9]+(?:\.[0-9]+)?/A', $expression, $match, null, $cursor)) {
4646
// numbers
4747
$number = (float) $match[0]; // floats
48-
if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) {
48+
if (preg_match('/^[0-9]+$/', $match[0]) && $number <= PHP_INT_MAX) {
4949
$number = (int) $match[0]; // integers lower than the maximum
5050
}
5151
$tokens[] = new Token(Token::NUMBER_TYPE, $number, $cursor + 1);

src/Symfony/Component/Form/DataMapperInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ interface DataMapperInterface
1919
/**
2020
* Maps properties of some data to a list of forms.
2121
*
22-
* @param mixed $data Structured data
23-
* @param FormInterface[] $forms A list of {@link FormInterface} instances
22+
* @param mixed $data Structured data
23+
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
2424
*
2525
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported.
2626
*/
@@ -29,8 +29,8 @@ public function mapDataToForms($data, $forms);
2929
/**
3030
* Maps the data of a list of forms into the properties of some data.
3131
*
32-
* @param FormInterface[] $forms A list of {@link FormInterface} instances
33-
* @param mixed $data Structured data
32+
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
33+
* @param mixed $data Structured data
3434
*
3535
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported.
3636
*/

src/Symfony/Component/Yaml/Parser.php

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,51 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
6464
if (false === preg_match('//u', $value)) {
6565
throw new ParseException('The YAML value does not appear to be valid UTF-8.');
6666
}
67+
68+
$this->refs = array();
69+
70+
$mbEncoding = null;
71+
$e = null;
72+
$data = null;
73+
74+
if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
75+
$mbEncoding = mb_internal_encoding();
76+
mb_internal_encoding('UTF-8');
77+
}
78+
79+
try {
80+
$data = $this->doParse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap);
81+
} catch (\Exception $e) {
82+
} catch (\Throwable $e) {
83+
}
84+
85+
if (null !== $mbEncoding) {
86+
mb_internal_encoding($mbEncoding);
87+
}
88+
89+
if (null !== $e) {
90+
throw $e;
91+
}
92+
93+
return $data;
94+
}
95+
96+
private function doParse($value, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false)
97+
{
6798
$this->currentLineNb = -1;
6899
$this->currentLine = '';
69100
$value = $this->cleanup($value);
70101
$this->lines = explode("\n", $value);
102+
$this->locallySkippedLineNumbers = array();
71103

72104
if (null === $this->totalNumberOfLines) {
73105
$this->totalNumberOfLines = count($this->lines);
74106
}
75107

76-
if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
77-
$mbEncoding = mb_internal_encoding();
78-
mb_internal_encoding('UTF-8');
79-
}
80-
81108
$data = array();
82109
$context = null;
83110
$allowOverwrite = false;
111+
84112
while ($this->moveToNextLine()) {
85113
if ($this->isCurrentLineEmpty()) {
86114
continue;
@@ -246,21 +274,13 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
246274
throw $e;
247275
}
248276

249-
if (isset($mbEncoding)) {
250-
mb_internal_encoding($mbEncoding);
251-
}
252-
253277
return $value;
254278
}
255279

256280
throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
257281
}
258282
}
259283

260-
if (isset($mbEncoding)) {
261-
mb_internal_encoding($mbEncoding);
262-
}
263-
264284
if ($objectForMap && !is_object($data) && 'mapping' === $context) {
265285
$object = new \stdClass();
266286

@@ -289,7 +309,7 @@ private function parseBlock($offset, $yaml, $exceptionOnInvalidType, $objectSupp
289309
$parser = new self($offset, $this->totalNumberOfLines, $skippedLineNumbers);
290310
$parser->refs = &$this->refs;
291311

292-
return $parser->parse($yaml, $exceptionOnInvalidType, $objectSupport, $objectForMap);
312+
return $parser->doParse($yaml, $exceptionOnInvalidType, $objectSupport, $objectForMap);
293313
}
294314

295315
/**

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,27 @@ public function testCanParseVeryLongValue()
12311231

12321232
$this->assertEquals($trickyVal, $arrayFromYaml);
12331233
}
1234+
1235+
/**
1236+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
1237+
* @expectedExceptionMessage Reference "foo" does not exist at line 2
1238+
*/
1239+
public function testParserCleansUpReferencesBetweenRuns()
1240+
{
1241+
$yaml = <<<YAML
1242+
foo: &foo
1243+
baz: foobar
1244+
bar:
1245+
<<: *foo
1246+
YAML;
1247+
$this->parser->parse($yaml);
1248+
1249+
$yaml = <<<YAML
1250+
bar:
1251+
<<: *foo
1252+
YAML;
1253+
$this->parser->parse($yaml);
1254+
}
12341255
}
12351256

12361257
class B

0 commit comments

Comments
 (0)
0