1 |
efrain |
1 |
# Interfaces
|
|
|
2 |
|
|
|
3 |
The purpose of this list is to help in finding the methods when working with PSR-7. This can be considered as a cheatsheet for PSR-7 interfaces.
|
|
|
4 |
|
|
|
5 |
The interfaces defined in PSR-7 are the following:
|
|
|
6 |
|
|
|
7 |
| Class Name | Description |
|
|
|
8 |
|---|---|
|
|
|
9 |
| [Psr\Http\Message\MessageInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagemessageinterface) | Representation of a HTTP message |
|
|
|
10 |
| [Psr\Http\Message\RequestInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagerequestinterface) | Representation of an outgoing, client-side request. |
|
|
|
11 |
| [Psr\Http\Message\ServerRequestInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageserverrequestinterface) | Representation of an incoming, server-side HTTP request. |
|
|
|
12 |
| [Psr\Http\Message\ResponseInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageresponseinterface) | Representation of an outgoing, server-side response. |
|
|
|
13 |
| [Psr\Http\Message\StreamInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagestreaminterface) | Describes a data stream |
|
|
|
14 |
| [Psr\Http\Message\UriInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageuriinterface) | Value object representing a URI. |
|
|
|
15 |
| [Psr\Http\Message\UploadedFileInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageuploadedfileinterface) | Value object representing a file uploaded through an HTTP request. |
|
|
|
16 |
|
|
|
17 |
## `Psr\Http\Message\MessageInterface` Methods
|
|
|
18 |
|
|
|
19 |
| Method Name | Description | Notes |
|
|
|
20 |
|------------------------------------| ----------- | ----- |
|
|
|
21 |
| `getProtocolVersion()` | Retrieve HTTP protocol version | 1.0 or 1.1 |
|
|
|
22 |
| `withProtocolVersion($version)` | Returns new message instance with given HTTP protocol version | |
|
|
|
23 |
| `getHeaders()` | Retrieve all HTTP Headers | [Request Header List](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields), [Response Header List](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Response_fields) |
|
|
|
24 |
| `hasHeader($name)` | Checks if HTTP Header with given name exists | |
|
|
|
25 |
| `getHeader($name)` | Retrieves a array with the values for a single header | |
|
|
|
26 |
| `getHeaderLine($name)` | Retrieves a comma-separated string of the values for a single header | |
|
|
|
27 |
| `withHeader($name, $value)` | Returns new message instance with given HTTP Header | if the header existed in the original instance, replaces the header value from the original message with the value provided when creating the new instance. |
|
|
|
28 |
| `withAddedHeader($name, $value)` | Returns new message instance with appended value to given header | If header already exists value will be appended, if not a new header will be created |
|
|
|
29 |
| `withoutHeader($name)` | Removes HTTP Header with given name| |
|
|
|
30 |
| `getBody()` | Retrieves the HTTP Message Body | Returns object implementing `StreamInterface`|
|
|
|
31 |
| `withBody(StreamInterface $body)` | Returns new message instance with given HTTP Message Body | |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
## `Psr\Http\Message\RequestInterface` Methods
|
|
|
35 |
|
|
|
36 |
Same methods as `Psr\Http\Message\MessageInterface` + the following methods:
|
|
|
37 |
|
|
|
38 |
| Method Name | Description | Notes |
|
|
|
39 |
|------------------------------------| ----------- | ----- |
|
|
|
40 |
| `getRequestTarget()` | Retrieves the message's request target | origin-form, absolute-form, authority-form, asterisk-form ([RFC7230](https://www.rfc-editor.org/rfc/rfc7230.txt)) |
|
|
|
41 |
| `withRequestTarget($requestTarget)` | Return a new message instance with the specific request-target | |
|
|
|
42 |
| `getMethod()` | Retrieves the HTTP method of the request. | GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE (defined in [RFC7231](https://tools.ietf.org/html/rfc7231)), PATCH (defined in [RFC5789](https://tools.ietf.org/html/rfc5789)) |
|
|
|
43 |
| `withMethod($method)` | Returns a new message instance with the provided HTTP method | |
|
|
|
44 |
| `getUri()` | Retrieves the URI instance | |
|
|
|
45 |
| `withUri(UriInterface $uri, $preserveHost = false)` | Returns a new message instance with the provided URI | |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
## `Psr\Http\Message\ServerRequestInterface` Methods
|
|
|
49 |
|
|
|
50 |
Same methods as `Psr\Http\Message\RequestInterface` + the following methods:
|
|
|
51 |
|
|
|
52 |
| Method Name | Description | Notes |
|
|
|
53 |
|------------------------------------| ----------- | ----- |
|
|
|
54 |
| `getServerParams() ` | Retrieve server parameters | Typically derived from `$_SERVER` |
|
|
|
55 |
| `getCookieParams()` | Retrieves cookies sent by the client to the server. | Typically derived from `$_COOKIES` |
|
|
|
56 |
| `withCookieParams(array $cookies)` | Returns a new request instance with the specified cookies | |
|
|
|
57 |
| `withQueryParams(array $query)` | Returns a new request instance with the specified query string arguments | |
|
|
|
58 |
| `getUploadedFiles()` | Retrieve normalized file upload data | |
|
|
|
59 |
| `withUploadedFiles(array $uploadedFiles)` | Returns a new request instance with the specified uploaded files | |
|
|
|
60 |
| `getParsedBody()` | Retrieve any parameters provided in the request body | |
|
|
|
61 |
| `withParsedBody($data)` | Returns a new request instance with the specified body parameters | |
|
|
|
62 |
| `getAttributes()` | Retrieve attributes derived from the request | |
|
|
|
63 |
| `getAttribute($name, $default = null)` | Retrieve a single derived request attribute | |
|
|
|
64 |
| `withAttribute($name, $value)` | Returns a new request instance with the specified derived request attribute | |
|
|
|
65 |
| `withoutAttribute($name)` | Returns a new request instance that without the specified derived request attribute | |
|
|
|
66 |
|
|
|
67 |
## `Psr\Http\Message\ResponseInterface` Methods:
|
|
|
68 |
|
|
|
69 |
Same methods as `Psr\Http\Message\MessageInterface` + the following methods:
|
|
|
70 |
|
|
|
71 |
| Method Name | Description | Notes |
|
|
|
72 |
|------------------------------------| ----------- | ----- |
|
|
|
73 |
| `getStatusCode()` | Gets the response status code. | |
|
|
|
74 |
| `withStatus($code, $reasonPhrase = '')` | Returns a new response instance with the specified status code and, optionally, reason phrase. | |
|
|
|
75 |
| `getReasonPhrase()` | Gets the response reason phrase associated with the status code. | |
|
|
|
76 |
|
|
|
77 |
## `Psr\Http\Message\StreamInterface` Methods
|
|
|
78 |
|
|
|
79 |
| Method Name | Description | Notes |
|
|
|
80 |
|------------------------------------| ----------- | ----- |
|
|
|
81 |
| `__toString()` | Reads all data from the stream into a string, from the beginning to end. | |
|
|
|
82 |
| `close()` | Closes the stream and any underlying resources. | |
|
|
|
83 |
| `detach()` | Separates any underlying resources from the stream. | |
|
|
|
84 |
| `getSize()` | Get the size of the stream if known. | |
|
|
|
85 |
| `eof()` | Returns true if the stream is at the end of the stream.| |
|
|
|
86 |
| `isSeekable()` | Returns whether or not the stream is seekable. | |
|
|
|
87 |
| `seek($offset, $whence = SEEK_SET)` | Seek to a position in the stream. | |
|
|
|
88 |
| `rewind()` | Seek to the beginning of the stream. | |
|
|
|
89 |
| `isWritable()` | Returns whether or not the stream is writable. | |
|
|
|
90 |
| `write($string)` | Write data to the stream. | |
|
|
|
91 |
| `isReadable()` | Returns whether or not the stream is readable. | |
|
|
|
92 |
| `read($length)` | Read data from the stream. | |
|
|
|
93 |
| `getContents()` | Returns the remaining contents in a string | |
|
|
|
94 |
| `getMetadata($key = null)()` | Get stream metadata as an associative array or retrieve a specific key. | |
|
|
|
95 |
|
|
|
96 |
## `Psr\Http\Message\UriInterface` Methods
|
|
|
97 |
|
|
|
98 |
| Method Name | Description | Notes |
|
|
|
99 |
|------------------------------------| ----------- | ----- |
|
|
|
100 |
| `getScheme()` | Retrieve the scheme component of the URI. | |
|
|
|
101 |
| `getAuthority()` | Retrieve the authority component of the URI. | |
|
|
|
102 |
| `getUserInfo()` | Retrieve the user information component of the URI. | |
|
|
|
103 |
| `getHost()` | Retrieve the host component of the URI. | |
|
|
|
104 |
| `getPort()` | Retrieve the port component of the URI. | |
|
|
|
105 |
| `getPath()` | Retrieve the path component of the URI. | |
|
|
|
106 |
| `getQuery()` | Retrieve the query string of the URI. | |
|
|
|
107 |
| `getFragment()` | Retrieve the fragment component of the URI. | |
|
|
|
108 |
| `withScheme($scheme)` | Return an instance with the specified scheme. | |
|
|
|
109 |
| `withUserInfo($user, $password = null)` | Return an instance with the specified user information. | |
|
|
|
110 |
| `withHost($host)` | Return an instance with the specified host. | |
|
|
|
111 |
| `withPort($port)` | Return an instance with the specified port. | |
|
|
|
112 |
| `withPath($path)` | Return an instance with the specified path. | |
|
|
|
113 |
| `withQuery($query)` | Return an instance with the specified query string. | |
|
|
|
114 |
| `withFragment($fragment)` | Return an instance with the specified URI fragment. | |
|
|
|
115 |
| `__toString()` | Return the string representation as a URI reference. | |
|
|
|
116 |
|
|
|
117 |
## `Psr\Http\Message\UploadedFileInterface` Methods
|
|
|
118 |
|
|
|
119 |
| Method Name | Description | Notes |
|
|
|
120 |
|------------------------------------| ----------- | ----- |
|
|
|
121 |
| `getStream()` | Retrieve a stream representing the uploaded file. | |
|
|
|
122 |
| `moveTo($targetPath)` | Move the uploaded file to a new location. | |
|
|
|
123 |
| `getSize()` | Retrieve the file size. | |
|
|
|
124 |
| `getError()` | Retrieve the error associated with the uploaded file. | |
|
|
|
125 |
| `getClientFilename()` | Retrieve the filename sent by the client. | |
|
|
|
126 |
| `getClientMediaType()` | Retrieve the media type sent by the client. | |
|
|
|
127 |
|
|
|
128 |
> `RequestInterface`, `ServerRequestInterface`, `ResponseInterface` extend `MessageInterface` because the `Request` and the `Response` are `HTTP Messages`.
|
|
|
129 |
> When using `ServerRequestInterface`, both `RequestInterface` and `Psr\Http\Message\MessageInterface` methods are considered.
|
|
|
130 |
|