AmqpCaster.php
1 year ago
ArgsStub.php
1 year ago
Caster.php
1 year ago
ClassStub.php
1 year ago
ConstStub.php
4 years ago
CutArrayStub.php
4 years ago
CutStub.php
4 years ago
DOMCaster.php
1 year ago
DateCaster.php
1 year ago
DoctrineCaster.php
1 year ago
DsCaster.php
1 year ago
DsPairStub.php
4 years ago
EnumStub.php
4 years ago
ExceptionCaster.php
1 year ago
FiberCaster.php
1 year ago
FrameStub.php
4 years ago
GmpCaster.php
1 year ago
ImagineCaster.php
4 years ago
ImgStub.php
1 year ago
IntlCaster.php
1 year ago
LinkStub.php
1 year ago
MemcachedCaster.php
1 year ago
MysqliCaster.php
1 year ago
PdoCaster.php
1 year ago
PgSqlCaster.php
1 year ago
ProxyManagerCaster.php
1 year ago
RdKafkaCaster.php
1 year ago
RedisCaster.php
1 year ago
ReflectionCaster.php
1 year ago
ResourceCaster.php
1 year ago
SplCaster.php
1 year ago
StubCaster.php
1 year ago
SymfonyCaster.php
1 year ago
TraceStub.php
1 year ago
UuidCaster.php
4 years ago
XmlReaderCaster.php
1 year ago
XmlResourceCaster.php
1 year ago
XmlReaderCaster.php
92 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | |
| 12 | namespace Symfony\Component\VarDumper\Caster; |
| 13 | |
| 14 | use Symfony\Component\VarDumper\Cloner\Stub; |
| 15 | |
| 16 | /** |
| 17 | * Casts XmlReader class to array representation. |
| 18 | * |
| 19 | * @author Baptiste Clavié <clavie.b@gmail.com> |
| 20 | * |
| 21 | * @final |
| 22 | */ |
| 23 | class XmlReaderCaster |
| 24 | { |
| 25 | private const NODE_TYPES = [ |
| 26 | \XMLReader::NONE => 'NONE', |
| 27 | \XMLReader::ELEMENT => 'ELEMENT', |
| 28 | \XMLReader::ATTRIBUTE => 'ATTRIBUTE', |
| 29 | \XMLReader::TEXT => 'TEXT', |
| 30 | \XMLReader::CDATA => 'CDATA', |
| 31 | \XMLReader::ENTITY_REF => 'ENTITY_REF', |
| 32 | \XMLReader::ENTITY => 'ENTITY', |
| 33 | \XMLReader::PI => 'PI (Processing Instruction)', |
| 34 | \XMLReader::COMMENT => 'COMMENT', |
| 35 | \XMLReader::DOC => 'DOC', |
| 36 | \XMLReader::DOC_TYPE => 'DOC_TYPE', |
| 37 | \XMLReader::DOC_FRAGMENT => 'DOC_FRAGMENT', |
| 38 | \XMLReader::NOTATION => 'NOTATION', |
| 39 | \XMLReader::WHITESPACE => 'WHITESPACE', |
| 40 | \XMLReader::SIGNIFICANT_WHITESPACE => 'SIGNIFICANT_WHITESPACE', |
| 41 | \XMLReader::END_ELEMENT => 'END_ELEMENT', |
| 42 | \XMLReader::END_ENTITY => 'END_ENTITY', |
| 43 | \XMLReader::XML_DECLARATION => 'XML_DECLARATION', |
| 44 | ]; |
| 45 | |
| 46 | public static function castXmlReader(\XMLReader $reader, array $a, Stub $stub, bool $isNested) |
| 47 | { |
| 48 | try { |
| 49 | $properties = [ |
| 50 | 'LOADDTD' => @$reader->getParserProperty(\XMLReader::LOADDTD), |
| 51 | 'DEFAULTATTRS' => @$reader->getParserProperty(\XMLReader::DEFAULTATTRS), |
| 52 | 'VALIDATE' => @$reader->getParserProperty(\XMLReader::VALIDATE), |
| 53 | 'SUBST_ENTITIES' => @$reader->getParserProperty(\XMLReader::SUBST_ENTITIES), |
| 54 | ]; |
| 55 | } catch (\Error $e) { |
| 56 | $properties = [ |
| 57 | 'LOADDTD' => false, |
| 58 | 'DEFAULTATTRS' => false, |
| 59 | 'VALIDATE' => false, |
| 60 | 'SUBST_ENTITIES' => false, |
| 61 | ]; |
| 62 | } |
| 63 | |
| 64 | $props = Caster::PREFIX_VIRTUAL.'parserProperties'; |
| 65 | $info = [ |
| 66 | 'localName' => $reader->localName, |
| 67 | 'prefix' => $reader->prefix, |
| 68 | 'nodeType' => new ConstStub(self::NODE_TYPES[$reader->nodeType], $reader->nodeType), |
| 69 | 'depth' => $reader->depth, |
| 70 | 'isDefault' => $reader->isDefault, |
| 71 | 'isEmptyElement' => \XMLReader::NONE === $reader->nodeType ? null : $reader->isEmptyElement, |
| 72 | 'xmlLang' => $reader->xmlLang, |
| 73 | 'attributeCount' => $reader->attributeCount, |
| 74 | 'value' => $reader->value, |
| 75 | 'namespaceURI' => $reader->namespaceURI, |
| 76 | 'baseURI' => $reader->baseURI ? new LinkStub($reader->baseURI) : $reader->baseURI, |
| 77 | $props => $properties, |
| 78 | ]; |
| 79 | |
| 80 | if ($info[$props] = Caster::filter($info[$props], Caster::EXCLUDE_EMPTY, [], $count)) { |
| 81 | $info[$props] = new EnumStub($info[$props]); |
| 82 | $info[$props]->cut = $count; |
| 83 | } |
| 84 | |
| 85 | $info = Caster::filter($info, Caster::EXCLUDE_EMPTY, [], $count); |
| 86 | // +2 because hasValue and hasAttributes are always filtered |
| 87 | $stub->cut += $count + 2; |
| 88 | |
| 89 | return $a + $info; |
| 90 | } |
| 91 | } |
| 92 |