| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | namespace Kint\Parser; |
| 27: | |
| 28: | use Kint\Object\BasicObject; |
| 29: | use Kint\Object\BlobObject; |
| 30: | use Kint\Object\Representation\Representation; |
| 31: | use SimpleXMLElement; |
| 32: | |
| 33: | class SimpleXMLElementPlugin extends Plugin |
| 34: | { |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | public static $verbose = false; |
| 41: | |
| 42: | public function getTypes() |
| 43: | { |
| 44: | return array('object'); |
| 45: | } |
| 46: | |
| 47: | public function getTriggers() |
| 48: | { |
| 49: | return Parser::TRIGGER_SUCCESS; |
| 50: | } |
| 51: | |
| 52: | public function parse(&$var, BasicObject &$o, $trigger) |
| 53: | { |
| 54: | if (!$var instanceof SimpleXMLElement) { |
| 55: | return; |
| 56: | } |
| 57: | |
| 58: | $o->hints[] = 'simplexml_element'; |
| 59: | |
| 60: | if (!self::$verbose) { |
| 61: | $o->removeRepresentation('properties'); |
| 62: | $o->removeRepresentation('iterator'); |
| 63: | $o->removeRepresentation('methods'); |
| 64: | } |
| 65: | |
| 66: | |
| 67: | $a = new Representation('Attributes'); |
| 68: | |
| 69: | $base_obj = new BasicObject(); |
| 70: | $base_obj->depth = $o->depth; |
| 71: | |
| 72: | if ($o->access_path) { |
| 73: | $base_obj->access_path = '(string) '.$o->access_path; |
| 74: | } |
| 75: | |
| 76: | if ($attribs = $var->attributes()) { |
| 77: | $attribs = \iterator_to_array($attribs); |
| 78: | $attribs = \array_map('strval', $attribs); |
| 79: | } else { |
| 80: | $attribs = array(); |
| 81: | } |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | $a->contents = $this->parser->parseDeep($attribs, $base_obj)->value->contents; |
| 87: | |
| 88: | $o->addRepresentation($a, 0); |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | $children = $var->children(); |
| 97: | |
| 98: | if ($o->value) { |
| 99: | $c = new Representation('Children'); |
| 100: | |
| 101: | foreach ($o->value->contents as $value) { |
| 102: | if ('@attributes' === $value->name) { |
| 103: | continue; |
| 104: | } |
| 105: | |
| 106: | if (isset($children->{$value->name})) { |
| 107: | $i = 0; |
| 108: | |
| 109: | while (isset($children->{$value->name}[$i])) { |
| 110: | $base_obj = new BasicObject(); |
| 111: | $base_obj->depth = $o->depth + 1; |
| 112: | $base_obj->name = $value->name; |
| 113: | if ($value->access_path) { |
| 114: | $base_obj->access_path = $value->access_path.'['.$i.']'; |
| 115: | } |
| 116: | |
| 117: | $value = $this->parser->parse($children->{$value->name}[$i], $base_obj); |
| 118: | |
| 119: | if ($value->access_path && 'string' === $value->type) { |
| 120: | $value->access_path = '(string) '.$value->access_path; |
| 121: | } |
| 122: | |
| 123: | $c->contents[] = $value; |
| 124: | |
| 125: | ++$i; |
| 126: | } |
| 127: | } |
| 128: | } |
| 129: | |
| 130: | $o->size = \count($c->contents); |
| 131: | |
| 132: | if (!$o->size) { |
| 133: | $o->size = null; |
| 134: | |
| 135: | if (\strlen((string) $var)) { |
| 136: | $base_obj = new BlobObject(); |
| 137: | $base_obj->depth = $o->depth + 1; |
| 138: | $base_obj->name = $o->name; |
| 139: | if ($o->access_path) { |
| 140: | $base_obj->access_path = '(string) '.$o->access_path; |
| 141: | } |
| 142: | |
| 143: | $value = (string) $var; |
| 144: | |
| 145: | $c = new Representation('Contents'); |
| 146: | $c->implicit_label = true; |
| 147: | $c->contents = array($this->parser->parseDeep($value, $base_obj)); |
| 148: | } |
| 149: | } |
| 150: | |
| 151: | $o->addRepresentation($c, 0); |
| 152: | } |
| 153: | } |
| 154: | } |
| 155: | |