@@ -22,53 +22,7 @@ This package requires PHP version 7.4 or later.
2222composer require httpsoft/http-response
2323```
2424
25- ## Usage Response
26-
27- ``` php
28- use HttpSoft\Response\Response;
29- use HttpSoft\Response\ResponseFactory;
30-
31- $response = ResponseFactory::create();
32- // equivalently to:
33- $response = new Response();
34- // default values
35- $response->getStatusCode(); // 200
36- $response->getReasonPhrase(); // 'OK'
37- $response->getBody()->getContents(); // ''
38- $response->getBody()->getMetadata('uri') // 'php://temp'
39- $response->getHeaders(); // []
40- $response->getProtocolVersion(); // '1.1'
41-
42- // Create with the passed parameters
43- $response = new Response(404, ['Content-Language' => 'en'], 'php://memory', '2');
44- $response->getStatusCode(); // 404
45- $response->getReasonPhrase(); // 'Not Found'
46- $response->getBody()->getContents(); // ''
47- $response->getBody()->getMetadata('uri') // 'php://memory'
48- $response->getHeaders(); // ['Content-Language' => ['en']]
49- $response->getProtocolVersion(); // '2'
50-
51- // Write to the response body:
52- $response->getBody()->write('Content');
53- $response->getBody()->getContents(); // 'Content'
54-
55- // With `Content-Type` header:
56- $newResponse = $response->withHeader('Content-Type', 'text/plain');
57- $newResponse->getHeaderLine('content-type'); // 'text/plain'
58- $newResponse->getHeaders(); // ['Content-Language' => ['ru'], 'Content-Type' => ['text/plain']]
59-
60- // With status code:
61- $newResponse = $response->withStatus(Response::STATUS_INTERNAL_SERVER_ERROR);
62- $newResponse->getStatusCode(); // 500
63- $newResponse->getReasonPhrase(); // 'Internal Server Error'
64-
65- // With status code and reason phrase:
66- $newResponse = $response->withStatus(599, 'Custom Phrase');
67- $newResponse->getStatusCode(); // 599
68- $newResponse->getReasonPhrase(); // 'Custom Phrase'
69- ```
70-
71- ## Create custom responses
25+ ## Usage
7226
7327``` php
7428// Create `Psr\Http\Message\ResponseInterface` instance from HTML:
0 commit comments