public function testGetDefaultValues() { $httpException = new InternalServerErrorException(); static::assertSame(500, $httpException->getStatusCode()); static::assertSame("Internal Server Error", $httpException->getReasonPhrase()); $response = response()->create('Hello World?'); $httpException = new InternalServerErrorException($response); static::assertSame(500, $httpException->getStatusCode()); static::assertSame("Hello World?", $httpException->getBody()->__toString()); }
/** * {@inheritdoc} */ public function responsify($response) { if ($response instanceof ResponseInterface) { return $response; } if (!isset($response)) { $response = ''; } while (is_callable($response)) { $nextResponse = call_user_func($response); $response = $nextResponse; } // int, float, boolean, string if (is_scalar($response)) { if ($response === true) { $response = 'true'; } elseif ($response === false) { $response = 'false'; } return response()->create((string) $response); } if ($response instanceof Generator) { return response()->generator($response); } if (is_array($response) || is_object($response)) { return response()->json($response); } if (is_resource($response)) { if ('stream' === get_resource_type($response)) { $mode = stream_get_meta_data($response)['mode']; // @todo use Stream if (strpos($mode, 'r') !== false || strpos($mode, '+') !== false) { $contents = ''; while (!feof($response)) { $contents .= fread($response, 1024); } return response()->create($contents); } } } throw new RuntimeException('Unsupported Type of Response.'); }
public function index(ServerRequestInterface $request) { return response()->create('index'); }
/** * {@inheritdoc} */ public function __invoke(ServerRequestInterface $request, Closure $next) { return response()->create("Fail..."); }
/** * @param \Generator $generator * @param int $status * @param array $headers * @return \Psr\Http\Message\ResponseInterface */ function generator(Generator $generator, $status = 200, array $headers = []) { return response()->generator($generator, $status, $headers); }