src/Server/Middleware/CallableMiddleware.php
public static function execute(callable $callable, array $arguments)
    {
        $return = call_user_func_array($callable, $arguments);

        if ($return instanceof ResponseInterface) {
            return $return;
        }

        $canBeUsedAsText = is_null($return)
            || is_scalar($return)
            || (is_object($return) && method_exists($return, '__toString'));

        if (! $canBeUsedAsText) {
            throw new UnexpectedValueException(
                'The value returned must be scalar or an object with __toString method'
            );
        }

        return new Response(200, new TextStream((string) $return));
    }
public static function execute(callable $callable, array $arguments)
    {
        $return = call_user_func_array($callable, $arguments);

        if ($return instanceof ResponseInterface) {
            return $return;
        }

        $canBeUsedAsText = is_null($return)
            || is_scalar($return)
            || (is_object($return) && method_exists($return, '__toString'));

        if (! $canBeUsedAsText) {
            throw new UnexpectedValueException(
                'The value returned must be scalar or an object with __toString method'
            );
        }

        return new Response(200, new TextStream((string) $return));
    }
@param callable $callable
@param array    $arguments

@return ResponseInterface