Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Dumper] Add support for XmlReader objets #18989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Prev Previous commit
Refactor XmlReader caster
Split main method into several sub methods when handling "special" cases
such as ATTRIBUTE, NONE or filtered elements
  • Loading branch information
Taluu committed Jun 21, 2016
commit c5222fee33f0fd0b9ce0631d74ea9f13670d6cfb
81 changes: 47 additions & 34 deletions 81 src/Symfony/Component/VarDumper/Caster/XmlReaderCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class XmlReaderCaster
);

private static $filteredTypes = array(
\XmlReader::ATTRIBUTE => true,
\XmlReader::ENTITY_REF => true,
\XmlReader::ENTITY => true,
\XmlReader::PI => true,
Expand All @@ -66,21 +65,19 @@ public static function castXmlReader(\XmlReader $reader, array $a, Stub $stub, $
));

if (\XmlReader::NONE === $reader->nodeType) {
return array(
'nodeType' => $nodeType,
Caster::PREFIX_VIRTUAL.'parserProperties' => $parserProperties,
);
return $a + self::castXmlNone($nodeType, $parserProperties);
}

if (\XmlReader::ATTRIBUTE === $reader->nodeType) {
return $a + self::castAttribute($reader, $nodeType, $parserProperties);
}

$infos = array(
'localName' => $reader->localName,
'nodeType' => $nodeType,

'depth' => $reader->depth,

'attributeCount' => $reader->attributeCount,
'hasAttributes' => $reader->hasAttributes,

'hasValue' => $reader->hasValue,
'isDefault' => $reader->isDefault,
'isEmptyElement' => $reader->isEmptyElement,
Expand All @@ -91,11 +88,8 @@ public static function castXmlReader(\XmlReader $reader, array $a, Stub $stub, $
$infos['namespaceURI'] = $reader->namespaceURI;
}

if ($reader->hasValue && (\XmlReader::TEXT === $reader->nodeType || \XmlReader::ATTRIBUTE === $reader->nodeType)) {
if ($reader->hasValue && \XmlReader::TEXT === $reader->nodeType) {
$infos['value'] = $reader->value;

unset($infos['localName']);
$stub->cut += 1;
}

if ($reader->hasAttributes) {
Expand All @@ -106,38 +100,57 @@ public static function castXmlReader(\XmlReader $reader, array $a, Stub $stub, $
}
}

if (isset(self::$filteredTypes[$reader->nodeType])) {
$infos = self::castFilteredElement($reader, $infos, $stub, $nodeType);
}

$infos[Caster::PREFIX_VIRTUAL.'parserProperties'] = $parserProperties;

if (isset(static::$filteredTypes[$reader->nodeType])) {
$cut = array(
'nodeType' => $nodeType,
'depth' => $reader->depth,
);
return $a + $infos;
}

if ('#text' !== $reader->localName) {
$cut['localName'] = $reader->localName;
}
private static function castXmlNone(ConstStub $type, EnumStub $properties)
{
return array(
'nodeType' => $type,
Caster::PREFIX_VIRTUAL.'parserProperties' => $properties,
);
}

if (\XmlReader::ATTRIBUTE === $reader->nodeType) {
$cut['hasValue'] = $reader->hasValue;
private static function castFilteredElement(\XmlReader $reader, array $infos, Stub $stub, ConstStub $type)
{
$cut = array(
'localName' => $reader->localName,
'nodeType' => $type,
'depth' => $reader->depth,
);

if ($reader->hasValue) {
$cut['value'] = $reader->value;
}
}
$stub->cut += count($infos) - count($cut);

if ('' !== $reader->prefix) {
$cut['prefix'] = $reader->prefix;
$cut['namespaceURI'] = $reader->namespaceURI;
}
return $cut;
}

$cut[Caster::PREFIX_VIRTUAL.'parserProperties'] = $parserProperties;
private static function castAttribute(\XmlReader $reader, ConstStub $type, EnumStub $properties)
{
$infos = array(
'localName' => $reader->localName,
'nodeType' => $type,
'depth' => $reader->depth,
'isDefault' => $reader->isDefault,
'hasValue' => $reader->hasValue,
);

$stub->cut += count($infos) - count($cut);
if ($reader->hasValue) {
$infos['value'] = $reader->value;
}

return $cut;
if ('' !== $reader->prefix) {
$infos['prefix'] = $reader->prefix;
$infos['namespaceURI'] = $reader->namespaceURI;
}

return $a + $infos;
$infos[Caster::PREFIX_VIRTUAL.'parserProperties'] = $properties;

return $infos;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function testTextElement()
{
$dump = <<<'DUMP'
XMLReader {
+localName: "#text"
+nodeType: TEXT
+depth: 2
+attributeCount: 0
Expand All @@ -164,7 +165,6 @@ public function testTextElement()
VALIDATE: false
SUBST_ENTITIES: false
}
…1
}

DUMP;
Expand All @@ -175,10 +175,11 @@ public function testTextElement()
}

/** @dataProvider textFilteredProvider */
public function testFilteredTextElement($nodeType, $nodeTypeName, $depth)
public function testFilteredTextElement($nodeType, $nodeTypeName, $depth, $localName)
{
$dump = <<<DUMP
XMLReader {
+localName: "$localName"
+nodeType: $nodeTypeName
+depth: $depth
parserProperties: {
Expand All @@ -187,7 +188,7 @@ public function testFilteredTextElement($nodeType, $nodeTypeName, $depth)
VALIDATE: false
SUBST_ENTITIES: false
}
6
5
}

DUMP;
Expand All @@ -200,7 +201,7 @@ public function testFilteredTextElement($nodeType, $nodeTypeName, $depth)
public function textFilteredProvider()
{
return array(
'Significant Whiltespace element' => array(\XmlReader::SIGNIFICANT_WHITESPACE, 'SIGNIFICANT_WHITESPACE', 1),
'Significant Whiltespace element' => array(\XmlReader::SIGNIFICANT_WHITESPACE, 'SIGNIFICANT_WHITESPACE', 1, '#text'),
);
}

Expand All @@ -209,9 +210,9 @@ public function testFilteredElement($localName, $nodeType, $nodeTypeName, $expan
{
$dump = <<<DUMP
XMLReader {
+localName: "$localName"
+nodeType: $nodeTypeName
+depth: $depth
+localName: "$localName"
parserProperties: {
LOADDTD: false
DEFAULTATTRS: false
Expand Down Expand Up @@ -239,9 +240,10 @@ public function testAttributeNode()
{
$dump = <<<'DUMP'
XMLReader {
+localName: "foo"
+nodeType: ATTRIBUTE
+depth: 2
+localName: "foo"
+isDefault: false
+hasValue: true
+value: "bar"
parserProperties: {
Expand All @@ -250,7 +252,6 @@ public function testAttributeNode()
VALIDATE: false
SUBST_ENTITIES: false
}
…4
}

DUMP;
Expand Down Expand Up @@ -314,4 +315,3 @@ public function tearDown()
$this->reader->close();
}
}

Morty Proxy This is a proxified and sanitized view of the page, visit original site.