public static function unserialize($input)
{
if (!$input) {
return null;
}
$input = trim($input);
$record = [];
$chunk = self::eatFirstKey($input);
if ($chunk[2]) {
// this is actually a class name.
$record['oClass'] = $chunk[0];
$input = $chunk[1];
$chunk = self::eatKey($input);
$key = $chunk[0];
$input = $chunk[1];
} else {
$key = $chunk[0];
$input = $chunk[1];
}
if (empty($key) && empty($input)) {
return $record;
}
$chunk = self::eatValue($input);
$value = $chunk[0];
$input = $chunk[1];
$record[$key] = $value;
while (strlen($input) > 0) {
if ($input[0] === ',') {
$input = substr($input, 1);
} else {
break;
}
$chunk = self::eatKey($input);
$key = $chunk[0];
$input = $chunk[1];
if (strlen($input) > 0) {
$chunk = self::eatValue($input);
$value = $chunk[0];
$input = $chunk[1];
$record[$key] = $value;
} else {
$record[$key] = null;
}
}
return $record;
}
/** * @Skip */ public function testDeserializeEmbeddedMaps() { // $this->markTestSkipped(); $x = 'V@"b":[{"xx":{"xxx":[1,2,"abc"]}}],"c":[{"yy":{"yyy":[3,4,"cde"]}}]'; $result = CSV::unserialize($x); $this->assertEquals(["oClass" => 'V', 'b' => [['xx' => ['xxx' => [1, 2, 'abc']]]], 'c' => [['yy' => ['yyy' => [3, 4, 'cde']]]]], $result); }