| 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: |  | 
| 31: | class SerializePlugin extends Plugin | 
| 32: | { | 
| 33: |  | 
| 34: |  | 
| 35: |  | 
| 36: |  | 
| 37: |  | 
| 38: |  | 
| 39: |  | 
| 40: |  | 
| 41: |  | 
| 42: |  | 
| 43: |  | 
| 44: |  | 
| 45: |  | 
| 46: |  | 
| 47: | public static $safe_mode = true; | 
| 48: | public static $options = array(true); | 
| 49: |  | 
| 50: | public function getTypes() | 
| 51: | { | 
| 52: | return array('string'); | 
| 53: | } | 
| 54: |  | 
| 55: | public function getTriggers() | 
| 56: | { | 
| 57: | return Parser::TRIGGER_SUCCESS; | 
| 58: | } | 
| 59: |  | 
| 60: | public function parse(&$var, BasicObject &$o, $trigger) | 
| 61: | { | 
| 62: | $trimmed = \rtrim($var); | 
| 63: |  | 
| 64: | if ('N;' !== $trimmed && !\preg_match('/^(?:[COabis]:\\d+[:;]|d:\\d+(?:\\.\\d+);)/', $trimmed)) { | 
| 65: | return; | 
| 66: | } | 
| 67: |  | 
| 68: | if (!self::$safe_mode || !\in_array($trimmed[0], array('C', 'O', 'a'), true)) { | 
| 69: |  | 
| 70: | if (KINT_PHP70) { | 
| 71: |  | 
| 72: | $data = @\unserialize($trimmed, self::$options); | 
| 73: | } else { | 
| 74: | $data = @\unserialize($trimmed); | 
| 75: | } | 
| 76: |  | 
| 77: | if (false === $data && 'b:0;' !== \substr($trimmed, 0, 4)) { | 
| 78: | return; | 
| 79: | } | 
| 80: | } | 
| 81: |  | 
| 82: | $base_obj = new BasicObject(); | 
| 83: | $base_obj->depth = $o->depth + 1; | 
| 84: | $base_obj->name = 'unserialize('.$o->name.')'; | 
| 85: |  | 
| 86: | if ($o->access_path) { | 
| 87: | $base_obj->access_path = 'unserialize('.$o->access_path; | 
| 88: | if (!KINT_PHP70 || self::$options === array(true)) { | 
| 89: | $base_obj->access_path .= ')'; | 
| 90: | } elseif (self::$options === array(false)) { | 
| 91: | $base_obj->access_path .= ', false)'; | 
| 92: | } else { | 
| 93: | $base_obj->access_path .= ', Serialize::$options)'; | 
| 94: | } | 
| 95: | } | 
| 96: |  | 
| 97: | $r = new Representation('Serialized'); | 
| 98: |  | 
| 99: | if (isset($data)) { | 
| 100: | $r->contents = $this->parser->parse($data, $base_obj); | 
| 101: | } else { | 
| 102: | $base_obj->hints[] = 'blacklist'; | 
| 103: | $r->contents = $base_obj; | 
| 104: | } | 
| 105: |  | 
| 106: | $o->addRepresentation($r, 0); | 
| 107: | } | 
| 108: | } | 
| 109: |  |