Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\VarDumper\Caster; Chris@0: Chris@0: use Symfony\Component\VarDumper\Cloner\Stub; Chris@0: Chris@0: /** Chris@0: * Casts XmlReader class to array representation. Chris@0: * Chris@0: * @author Baptiste ClaviƩ Chris@0: */ Chris@0: class XmlReaderCaster Chris@0: { Chris@17: private static $nodeTypes = [ Chris@0: \XMLReader::NONE => 'NONE', Chris@0: \XMLReader::ELEMENT => 'ELEMENT', Chris@0: \XMLReader::ATTRIBUTE => 'ATTRIBUTE', Chris@0: \XMLReader::TEXT => 'TEXT', Chris@0: \XMLReader::CDATA => 'CDATA', Chris@0: \XMLReader::ENTITY_REF => 'ENTITY_REF', Chris@0: \XMLReader::ENTITY => 'ENTITY', Chris@0: \XMLReader::PI => 'PI (Processing Instruction)', Chris@0: \XMLReader::COMMENT => 'COMMENT', Chris@0: \XMLReader::DOC => 'DOC', Chris@0: \XMLReader::DOC_TYPE => 'DOC_TYPE', Chris@0: \XMLReader::DOC_FRAGMENT => 'DOC_FRAGMENT', Chris@0: \XMLReader::NOTATION => 'NOTATION', Chris@0: \XMLReader::WHITESPACE => 'WHITESPACE', Chris@0: \XMLReader::SIGNIFICANT_WHITESPACE => 'SIGNIFICANT_WHITESPACE', Chris@0: \XMLReader::END_ELEMENT => 'END_ELEMENT', Chris@0: \XMLReader::END_ENTITY => 'END_ENTITY', Chris@0: \XMLReader::XML_DECLARATION => 'XML_DECLARATION', Chris@17: ]; Chris@0: Chris@0: public static function castXmlReader(\XMLReader $reader, array $a, Stub $stub, $isNested) Chris@0: { Chris@0: $props = Caster::PREFIX_VIRTUAL.'parserProperties'; Chris@17: $info = [ Chris@0: 'localName' => $reader->localName, Chris@0: 'prefix' => $reader->prefix, Chris@0: 'nodeType' => new ConstStub(self::$nodeTypes[$reader->nodeType], $reader->nodeType), Chris@0: 'depth' => $reader->depth, Chris@0: 'isDefault' => $reader->isDefault, Chris@0: 'isEmptyElement' => \XMLReader::NONE === $reader->nodeType ? null : $reader->isEmptyElement, Chris@0: 'xmlLang' => $reader->xmlLang, Chris@0: 'attributeCount' => $reader->attributeCount, Chris@0: 'value' => $reader->value, Chris@0: 'namespaceURI' => $reader->namespaceURI, Chris@0: 'baseURI' => $reader->baseURI ? new LinkStub($reader->baseURI) : $reader->baseURI, Chris@17: $props => [ Chris@0: 'LOADDTD' => $reader->getParserProperty(\XMLReader::LOADDTD), Chris@0: 'DEFAULTATTRS' => $reader->getParserProperty(\XMLReader::DEFAULTATTRS), Chris@0: 'VALIDATE' => $reader->getParserProperty(\XMLReader::VALIDATE), Chris@0: 'SUBST_ENTITIES' => $reader->getParserProperty(\XMLReader::SUBST_ENTITIES), Chris@17: ], Chris@17: ]; Chris@0: Chris@17: if ($info[$props] = Caster::filter($info[$props], Caster::EXCLUDE_EMPTY, [], $count)) { Chris@0: $info[$props] = new EnumStub($info[$props]); Chris@0: $info[$props]->cut = $count; Chris@0: } Chris@0: Chris@17: $info = Caster::filter($info, Caster::EXCLUDE_EMPTY, [], $count); Chris@0: // +2 because hasValue and hasAttributes are always filtered Chris@0: $stub->cut += $count + 2; Chris@0: Chris@0: return $a + $info; Chris@0: } Chris@0: }