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