ManaPHP\Serializer\Adapter\JsonPhp::serialize PHP Method

serialize() public method

public serialize ( mixed $data ) : string
$data mixed
return string
    public function serialize($data)
    {
        if (is_scalar($data) || $data === null) {
            $wrappedData = ['__wrapper__' => $data];
            $serialized = json_encode($wrappedData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        } elseif ($this->_isCanJsonSafely($data)) {
            $serialized = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
            if ($serialized === false) {
                throw new JsonPhpException('json_encode failed: :message', ['message' => json_last_error_msg()]);
            }
        } else {
            $serialized = serialize($data);
        }
        return $serialized;
    }