PhpOrient\Protocols\Binary\Serialization\CSV::unserialize PHP Method

unserialize() public static method

Deserialize a record.
public static unserialize ( string $input ) : array | null
$input string The input to un-serialize.
return array | null The un-serialized document, or null if the input is empty.
    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;
    }

Usage Example

Example #1
0
 /**
  * @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);
 }
All Usage Examples Of PhpOrient\Protocols\Binary\Serialization\CSV::unserialize