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

Commit 5be65ba

Browse filesBrowse files
[VarDumper] Add Caster for XML-parser resources
1 parent 59ca5b3 commit 5be65ba
Copy full SHA for 5be65ba

File tree

Expand file treeCollapse file tree

3 files changed

+74
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+74
-0
lines changed

‎src/Symfony/Component/VarDumper/Caster/ResourceCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ResourceCaster.php
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@
2020
*/
2121
class ResourceCaster
2222
{
23+
private static $xmlErrors = array(
24+
'XML_ERROR_NONE',
25+
'XML_ERROR_NO_MEMORY',
26+
'XML_ERROR_SYNTAX',
27+
'XML_ERROR_NO_ELEMENTS',
28+
'XML_ERROR_INVALID_TOKEN',
29+
'XML_ERROR_UNCLOSED_TOKEN',
30+
'XML_ERROR_PARTIAL_CHAR',
31+
'XML_ERROR_TAG_MISMATCH',
32+
'XML_ERROR_DUPLICATE_ATTRIBUTE',
33+
'XML_ERROR_JUNK_AFTER_DOC_ELEMENT',
34+
'XML_ERROR_PARAM_ENTITY_REF',
35+
'XML_ERROR_UNDEFINED_ENTITY',
36+
'XML_ERROR_RECURSIVE_ENTITY_REF',
37+
'XML_ERROR_ASYNC_ENTITY',
38+
'XML_ERROR_BAD_CHAR_REF',
39+
'XML_ERROR_BINARY_ENTITY_REF',
40+
'XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF',
41+
'XML_ERROR_MISPLACED_XML_PI',
42+
'XML_ERROR_UNKNOWN_ENCODING',
43+
'XML_ERROR_INCORRECT_ENCODING',
44+
'XML_ERROR_UNCLOSED_CDATA_SECTION',
45+
'XML_ERROR_EXTERNAL_ENTITY_HANDLING',
46+
);
47+
2348
public static function castCurl($h, array $a, Stub $stub, $isNested)
2449
{
2550
return curl_getinfo($h);
@@ -64,4 +89,18 @@ public static function castMysqlLink($h, array $a, Stub $stub, $isNested)
6489

6590
return $a;
6691
}
92+
93+
public static function castXml($h, array $a, Stub $stub, $isNested)
94+
{
95+
$a['current_byte_index'] = xml_get_current_byte_index($h);
96+
$a['current_column_number'] = xml_get_current_column_number($h);
97+
$a['current_line_number'] = xml_get_current_line_number($h);
98+
$a['error_code'] = xml_get_error_code($h);
99+
100+
if (isset(self::$xmlErrors[$a['error_code']])) {
101+
$a['error_code'] = new ConstStub(self::$xmlErrors[$a['error_code']], $a['error_code']);
102+
}
103+
104+
return $a;
105+
}
67106
}

‎src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ abstract class AbstractCloner implements ClonerInterface
7878
':process' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castProcess',
7979
':stream' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castStream',
8080
':stream-context' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castStreamContext',
81+
':xml' => 'Symfony\Component\VarDumper\Caster\ResourceCaster::castXml',
8182
);
8283

8384
protected $maxItems = 2500;

‎src/Symfony/Component/VarDumper/Tests/CliDumperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/CliDumperTest.php
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,40 @@ public function testGet()
102102
b"bin-key-é" => ""
103103
]
104104
105+
EOTXT
106+
,
107+
$out
108+
);
109+
}
110+
111+
public function testXmlResource()
112+
{
113+
if (!extension_loaded('xml')) {
114+
$this->markTestSkipped('xml extension is required');
115+
}
116+
117+
$var = xml_parser_create();
118+
$ref = (int) $var;
119+
120+
$dumper = new CliDumper();
121+
$dumper->setColors(false);
122+
$cloner = new VarCloner();
123+
124+
$data = $cloner->cloneVar($var);
125+
$out = fopen('php://memory', 'r+b');
126+
$dumper->dump($data, $out);
127+
rewind($out);
128+
$out = stream_get_contents($out);
129+
130+
$this->assertSame(
131+
<<<EOTXT
132+
:xml {@{$ref}
133+
current_byte_index: 0
134+
current_column_number: 1
135+
current_line_number: 1
136+
error_code: XML_ERROR_NONE
137+
}
138+
105139
EOTXT
106140
,
107141
$out

0 commit comments

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