Merge branch '2.8' into 3.2
* 2.8: don't keep internal state between parser runs Add \Traversable typehint to phpdoc [ExpressionLanguage] Avoid dependency on ctype [Debug] Fix php notice [VarDumper] Relax tests to adapt for php 7.1rc4
This commit is contained in:
commit
d41a3a56c2
@ -151,7 +151,7 @@ class DebugClassLoader
|
|||||||
|
|
||||||
$exists = class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false);
|
$exists = class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false);
|
||||||
|
|
||||||
if ('\\' === $class[0]) {
|
if ($class && '\\' === $class[0]) {
|
||||||
$class = substr($class, 1);
|
$class = substr($class, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class Lexer
|
|||||||
if (preg_match('/[0-9]+(?:\.[0-9]+)?/A', $expression, $match, null, $cursor)) {
|
if (preg_match('/[0-9]+(?:\.[0-9]+)?/A', $expression, $match, null, $cursor)) {
|
||||||
// numbers
|
// numbers
|
||||||
$number = (float) $match[0]; // floats
|
$number = (float) $match[0]; // floats
|
||||||
if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) {
|
if (preg_match('/^[0-9]+$/', $match[0]) && $number <= PHP_INT_MAX) {
|
||||||
$number = (int) $match[0]; // integers lower than the maximum
|
$number = (int) $match[0]; // integers lower than the maximum
|
||||||
}
|
}
|
||||||
$tokens[] = new Token(Token::NUMBER_TYPE, $number, $cursor + 1);
|
$tokens[] = new Token(Token::NUMBER_TYPE, $number, $cursor + 1);
|
||||||
|
@ -19,8 +19,8 @@ interface DataMapperInterface
|
|||||||
/**
|
/**
|
||||||
* Maps properties of some data to a list of forms.
|
* Maps properties of some data to a list of forms.
|
||||||
*
|
*
|
||||||
* @param mixed $data Structured data
|
* @param mixed $data Structured data
|
||||||
* @param FormInterface[] $forms A list of {@link FormInterface} instances
|
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
|
||||||
*
|
*
|
||||||
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported.
|
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported.
|
||||||
*/
|
*/
|
||||||
@ -29,8 +29,8 @@ interface DataMapperInterface
|
|||||||
/**
|
/**
|
||||||
* Maps the data of a list of forms into the properties of some data.
|
* Maps the data of a list of forms into the properties of some data.
|
||||||
*
|
*
|
||||||
* @param FormInterface[] $forms A list of {@link FormInterface} instances
|
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
|
||||||
* @param mixed $data Structured data
|
* @param mixed $data Structured data
|
||||||
*
|
*
|
||||||
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported.
|
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported.
|
||||||
*/
|
*/
|
||||||
|
@ -293,9 +293,7 @@ stream resource {@{$ref}
|
|||||||
: } catch (%s \$e) {
|
: } catch (%s \$e) {
|
||||||
}
|
}
|
||||||
%sCliDumperTest.php:{$line}: {
|
%sCliDumperTest.php:{$line}: {
|
||||||
: }
|
%A
|
||||||
: };'),
|
|
||||||
: ));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,23 +87,51 @@ class Parser
|
|||||||
if (false === preg_match('//u', $value)) {
|
if (false === preg_match('//u', $value)) {
|
||||||
throw new ParseException('The YAML value does not appear to be valid UTF-8.');
|
throw new ParseException('The YAML value does not appear to be valid UTF-8.');
|
||||||
}
|
}
|
||||||
$this->currentLineNb = -1;
|
|
||||||
$this->currentLine = '';
|
|
||||||
$value = $this->cleanup($value);
|
|
||||||
$this->lines = explode("\n", $value);
|
|
||||||
|
|
||||||
if (null === $this->totalNumberOfLines) {
|
$this->refs = array();
|
||||||
$this->totalNumberOfLines = count($this->lines);
|
|
||||||
}
|
$mbEncoding = null;
|
||||||
|
$e = null;
|
||||||
|
$data = null;
|
||||||
|
|
||||||
if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
|
if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
|
||||||
$mbEncoding = mb_internal_encoding();
|
$mbEncoding = mb_internal_encoding();
|
||||||
mb_internal_encoding('UTF-8');
|
mb_internal_encoding('UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$data = $this->doParse($value, $flags);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $mbEncoding) {
|
||||||
|
mb_internal_encoding($mbEncoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function doParse($value, $flags)
|
||||||
|
{
|
||||||
|
$this->currentLineNb = -1;
|
||||||
|
$this->currentLine = '';
|
||||||
|
$value = $this->cleanup($value);
|
||||||
|
$this->lines = explode("\n", $value);
|
||||||
|
$this->locallySkippedLineNumbers = array();
|
||||||
|
|
||||||
|
if (null === $this->totalNumberOfLines) {
|
||||||
|
$this->totalNumberOfLines = count($this->lines);
|
||||||
|
}
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
$context = null;
|
$context = null;
|
||||||
$allowOverwrite = false;
|
$allowOverwrite = false;
|
||||||
|
|
||||||
while ($this->moveToNextLine()) {
|
while ($this->moveToNextLine()) {
|
||||||
if ($this->isCurrentLineEmpty()) {
|
if ($this->isCurrentLineEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
@ -279,10 +307,6 @@ class Parser
|
|||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($mbEncoding)) {
|
|
||||||
mb_internal_encoding($mbEncoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,10 +314,6 @@ class Parser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($mbEncoding)) {
|
|
||||||
mb_internal_encoding($mbEncoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Yaml::PARSE_OBJECT_FOR_MAP & $flags && !is_object($data) && 'mapping' === $context) {
|
if (Yaml::PARSE_OBJECT_FOR_MAP & $flags && !is_object($data) && 'mapping' === $context) {
|
||||||
$object = new \stdClass();
|
$object = new \stdClass();
|
||||||
|
|
||||||
@ -322,7 +342,7 @@ class Parser
|
|||||||
$parser = new self($offset, $this->totalNumberOfLines, $skippedLineNumbers);
|
$parser = new self($offset, $this->totalNumberOfLines, $skippedLineNumbers);
|
||||||
$parser->refs = &$this->refs;
|
$parser->refs = &$this->refs;
|
||||||
|
|
||||||
return $parser->parse($yaml, $flags);
|
return $parser->doParse($yaml, $flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1490,6 +1490,27 @@ EOT;
|
|||||||
|
|
||||||
$this->assertEquals($trickyVal, $arrayFromYaml);
|
$this->assertEquals($trickyVal, $arrayFromYaml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||||
|
* @expectedExceptionMessage Reference "foo" does not exist at line 2
|
||||||
|
*/
|
||||||
|
public function testParserCleansUpReferencesBetweenRuns()
|
||||||
|
{
|
||||||
|
$yaml = <<<YAML
|
||||||
|
foo: &foo
|
||||||
|
baz: foobar
|
||||||
|
bar:
|
||||||
|
<<: *foo
|
||||||
|
YAML;
|
||||||
|
$this->parser->parse($yaml);
|
||||||
|
|
||||||
|
$yaml = <<<YAML
|
||||||
|
bar:
|
||||||
|
<<: *foo
|
||||||
|
YAML;
|
||||||
|
$this->parser->parse($yaml);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class B
|
class B
|
||||||
|
Reference in New Issue
Block a user