Chris@0
|
1 <?php
|
Chris@0
|
2 /*
|
Chris@0
|
3 * This file is part of the Symfony package.
|
Chris@0
|
4 *
|
Chris@0
|
5 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
6 *
|
Chris@0
|
7 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
8 * file that was distributed with this source code.
|
Chris@0
|
9 */
|
Chris@0
|
10
|
Chris@0
|
11 namespace Symfony\Component\VarDumper\Caster;
|
Chris@0
|
12
|
Chris@0
|
13 use Symfony\Component\VarDumper\Cloner\Stub;
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * Casts XmlReader class to array representation.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @author Baptiste ClaviƩ <clavie.b@gmail.com>
|
Chris@0
|
19 */
|
Chris@0
|
20 class XmlReaderCaster
|
Chris@0
|
21 {
|
Chris@17
|
22 private static $nodeTypes = [
|
Chris@0
|
23 \XMLReader::NONE => 'NONE',
|
Chris@0
|
24 \XMLReader::ELEMENT => 'ELEMENT',
|
Chris@0
|
25 \XMLReader::ATTRIBUTE => 'ATTRIBUTE',
|
Chris@0
|
26 \XMLReader::TEXT => 'TEXT',
|
Chris@0
|
27 \XMLReader::CDATA => 'CDATA',
|
Chris@0
|
28 \XMLReader::ENTITY_REF => 'ENTITY_REF',
|
Chris@0
|
29 \XMLReader::ENTITY => 'ENTITY',
|
Chris@0
|
30 \XMLReader::PI => 'PI (Processing Instruction)',
|
Chris@0
|
31 \XMLReader::COMMENT => 'COMMENT',
|
Chris@0
|
32 \XMLReader::DOC => 'DOC',
|
Chris@0
|
33 \XMLReader::DOC_TYPE => 'DOC_TYPE',
|
Chris@0
|
34 \XMLReader::DOC_FRAGMENT => 'DOC_FRAGMENT',
|
Chris@0
|
35 \XMLReader::NOTATION => 'NOTATION',
|
Chris@0
|
36 \XMLReader::WHITESPACE => 'WHITESPACE',
|
Chris@0
|
37 \XMLReader::SIGNIFICANT_WHITESPACE => 'SIGNIFICANT_WHITESPACE',
|
Chris@0
|
38 \XMLReader::END_ELEMENT => 'END_ELEMENT',
|
Chris@0
|
39 \XMLReader::END_ENTITY => 'END_ENTITY',
|
Chris@0
|
40 \XMLReader::XML_DECLARATION => 'XML_DECLARATION',
|
Chris@17
|
41 ];
|
Chris@0
|
42
|
Chris@0
|
43 public static function castXmlReader(\XMLReader $reader, array $a, Stub $stub, $isNested)
|
Chris@0
|
44 {
|
Chris@0
|
45 $props = Caster::PREFIX_VIRTUAL.'parserProperties';
|
Chris@17
|
46 $info = [
|
Chris@0
|
47 'localName' => $reader->localName,
|
Chris@0
|
48 'prefix' => $reader->prefix,
|
Chris@0
|
49 'nodeType' => new ConstStub(self::$nodeTypes[$reader->nodeType], $reader->nodeType),
|
Chris@0
|
50 'depth' => $reader->depth,
|
Chris@0
|
51 'isDefault' => $reader->isDefault,
|
Chris@0
|
52 'isEmptyElement' => \XMLReader::NONE === $reader->nodeType ? null : $reader->isEmptyElement,
|
Chris@0
|
53 'xmlLang' => $reader->xmlLang,
|
Chris@0
|
54 'attributeCount' => $reader->attributeCount,
|
Chris@0
|
55 'value' => $reader->value,
|
Chris@0
|
56 'namespaceURI' => $reader->namespaceURI,
|
Chris@0
|
57 'baseURI' => $reader->baseURI ? new LinkStub($reader->baseURI) : $reader->baseURI,
|
Chris@17
|
58 $props => [
|
Chris@0
|
59 'LOADDTD' => $reader->getParserProperty(\XMLReader::LOADDTD),
|
Chris@0
|
60 'DEFAULTATTRS' => $reader->getParserProperty(\XMLReader::DEFAULTATTRS),
|
Chris@0
|
61 'VALIDATE' => $reader->getParserProperty(\XMLReader::VALIDATE),
|
Chris@0
|
62 'SUBST_ENTITIES' => $reader->getParserProperty(\XMLReader::SUBST_ENTITIES),
|
Chris@17
|
63 ],
|
Chris@17
|
64 ];
|
Chris@0
|
65
|
Chris@17
|
66 if ($info[$props] = Caster::filter($info[$props], Caster::EXCLUDE_EMPTY, [], $count)) {
|
Chris@0
|
67 $info[$props] = new EnumStub($info[$props]);
|
Chris@0
|
68 $info[$props]->cut = $count;
|
Chris@0
|
69 }
|
Chris@0
|
70
|
Chris@17
|
71 $info = Caster::filter($info, Caster::EXCLUDE_EMPTY, [], $count);
|
Chris@0
|
72 // +2 because hasValue and hasAttributes are always filtered
|
Chris@0
|
73 $stub->cut += $count + 2;
|
Chris@0
|
74
|
Chris@0
|
75 return $a + $info;
|
Chris@0
|
76 }
|
Chris@0
|
77 }
|