| 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\Representation\Representation; |
| 30: | use Traversable; |
| 31: | |
| 32: | class IteratorPlugin extends Plugin |
| 33: | { |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | public static $blacklist = array( |
| 44: | 'DOMNamedNodeMap', |
| 45: | 'DOMNodeList', |
| 46: | 'mysqli_result', |
| 47: | 'PDOStatement', |
| 48: | 'SplFileObject', |
| 49: | ); |
| 50: | |
| 51: | public function getTypes() |
| 52: | { |
| 53: | return array('object'); |
| 54: | } |
| 55: | |
| 56: | public function getTriggers() |
| 57: | { |
| 58: | return Parser::TRIGGER_SUCCESS; |
| 59: | } |
| 60: | |
| 61: | public function parse(&$var, BasicObject &$o, $trigger) |
| 62: | { |
| 63: | if (!$var instanceof Traversable) { |
| 64: | return; |
| 65: | } |
| 66: | |
| 67: | foreach (self::$blacklist as $class) { |
| 68: | if ($var instanceof $class) { |
| 69: | $b = new BasicObject(); |
| 70: | $b->name = $class.' Iterator Contents'; |
| 71: | $b->access_path = 'iterator_to_array('.$o->access_path.', true)'; |
| 72: | $b->depth = $o->depth + 1; |
| 73: | $b->hints[] = 'blacklist'; |
| 74: | |
| 75: | $r = new Representation('Iterator'); |
| 76: | $r->contents = array($b); |
| 77: | |
| 78: | $o->addRepresentation($r); |
| 79: | |
| 80: | return; |
| 81: | } |
| 82: | } |
| 83: | |
| 84: | |
| 85: | $data = \iterator_to_array($var); |
| 86: | |
| 87: | if (false === $data) { |
| 88: | return; |
| 89: | } |
| 90: | |
| 91: | $base_obj = new BasicObject(); |
| 92: | $base_obj->depth = $o->depth; |
| 93: | |
| 94: | if ($o->access_path) { |
| 95: | $base_obj->access_path = 'iterator_to_array('.$o->access_path.')'; |
| 96: | } |
| 97: | |
| 98: | $r = new Representation('Iterator'); |
| 99: | $r->contents = $this->parser->parse($data, $base_obj); |
| 100: | $r->contents = $r->contents->value->contents; |
| 101: | |
| 102: | $primary = $o->getRepresentations(); |
| 103: | $primary = \reset($primary); |
| 104: | if ($primary && $primary === $o->value && $primary->contents === array()) { |
| 105: | $o->addRepresentation($r, 0); |
| 106: | } else { |
| 107: | $o->addRepresentation($r); |
| 108: | } |
| 109: | } |
| 110: | } |
| 111: | |