public static function serialize(\Closure $closure, string $type = null): string
    {
        self::$serializeType = $type;

        $serialized = Serialize::encode(new SerializableClosure($closure), $type);

        if ($serialized === null) {
            throw new \RuntimeException('The closure could not be serialized.');
        }

        return $serialized;
    }