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

eatRecord() protected static method

Consume an embedded record.
protected static eatRecord ( string $input ) : array
$input string The input to unserialize.
return array The collected record and any remaining content.
    protected static function eatRecord($input)
    {
        $record = [];
        $input = ltrim($input, ' ');
        if ($input[0] === ')') {
            // this is an empty record.
            return [$record, substr($input, 1)];
        }
        $chunk = self::eatFirstKey($input);
        if ($chunk[2]) {
            // this is actually a class name.
            $record['oClass'] = $chunk[0];
            $input = ltrim($chunk[1], ' ');
            if ($input[0] === ')') {
                return [$record, substr($input, 1)];
            }
            $chunk = self::eatKey($input);
            $key = $chunk[0];
            $input = $chunk[1];
        } else {
            $key = $chunk[0];
            $input = $chunk[1];
        }
        $chunk = self::eatValue($input);
        $value = $chunk[0];
        $input = ltrim($chunk[1], ' ');
        $record[$key] = $value;
        while (strlen($input) > 0) {
            if ($input[0] === ',') {
                $input = ltrim(substr($input, 1), ' ');
            } elseif ($input[0] === ')') {
                $input = ltrim(substr($input, 1), ' ');
                break;
            }
            $chunk = self::eatKey($input);
            $key = $chunk[0];
            $input = ltrim($chunk[1], ' ');
            if (strlen($input) > 0) {
                $chunk = self::eatValue($input);
                $value = $chunk[0];
                $input = $chunk[1];
                $record[$key] = $value;
            } else {
                $record[$key] = null;
            }
        }
        $payload = [];
        if (isset($record['oClass'])) {
            $payload['oClass'] = $record['oClass'];
            unset($record['oClass']);
        }
        if (isset($record['@type'])) {
            $payload['type'] = $record['@type'];
            unset($record['@type']);
        }
        $payload['oData'] = $record;
        $record = \PhpOrient\Protocols\Binary\Data\Record::fromConfig($payload);
        return [$record, $input];
    }