Skip to content

Commit f3961cd

Browse files
author
Phil Sturgeon
committed
Initial import
0 parents  commit f3961cd

File tree

8 files changed

+411
-0
lines changed

8 files changed

+411
-0
lines changed

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2014 PHP Framework Interoperability Group
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PSR Http Message
2+
================
3+
4+
This repository holds all interfaces/classes/traits related to
5+
[PSR-7](http://www.php-fig.org/psr/psr-7/).
6+
7+
Note that this is not a HTTP message implementation of its own. It is merely an
8+
interface that describes a HTTP message. See the specification for more details.
9+
10+
Usage
11+
-----
12+
13+
We'll certainly need some stuff in here.

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "psr/http-message",
3+
"description": "Common interface for HTTP messages",
4+
"keywords": ["psr", "psr-7", "http", "http-message", "request", "response"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "PHP-FIG",
9+
"homepage": "http://www.php-fig.org/"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"Psr\\HttpMessage\\": "src"
15+
}
16+
},
17+
"extra": {
18+
"branch-alias": {
19+
"dev-master": "1.0.x-dev"
20+
}
21+
}
22+
}

src/InvalidArgumentException.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Psr\HttpMessage;
4+
5+
class InvalidArgumentException extends \InvalidArgumentException
6+
{
7+
}

src/MessageInterface.php

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
3+
namespace Psr\HttpMessage;
4+
5+
/**
6+
* HTTP messages consist of requests from a client to a server and responses
7+
* from a server to a client.
8+
*/
9+
interface MessageInterface
10+
{
11+
/**
12+
* Gets the HTTP protocol version as a string containing only the HTTP
13+
* version (e.g., "1.1", "1.0").
14+
*
15+
* @return string HTTP protocol version.
16+
*/
17+
public function getProtocolVersion();
18+
19+
/**
20+
* Gets the body of the message.
21+
*
22+
* @return StreamInterface|null Returns the body, or null if not set.
23+
*/
24+
public function getBody();
25+
26+
/**
27+
* Sets the body of the message.
28+
*
29+
* The body MUST be a StreamInterface object. Setting the body to null MUST
30+
* remove the existing body.
31+
*
32+
* @param StreamInterface|null $body Body.
33+
*
34+
* @return self Returns the message.
35+
*/
36+
public function setBody(StreamInterface $body = null);
37+
38+
/**
39+
* Gets all message headers.
40+
*
41+
* The keys represent the header name as it will be sent over the wire, and
42+
* each value is an array of strings associated with the header.
43+
*
44+
* // Represent the headers as a string
45+
* foreach ($message->getHeaders() as $name => $values) {
46+
* echo $name . ": " . implode(", ", $values);
47+
* }
48+
*
49+
* @return array Returns an associative array of the message's headers.
50+
*/
51+
public function getHeaders();
52+
53+
/**
54+
* Checks if a header exists by the given case-insensitive name.
55+
*
56+
* @param string $header Case-insensitive header name.
57+
*
58+
* @return bool Returns true if any header names match the given header
59+
* name using a case-insensitive string comparison. Returns false if
60+
* no matching header name is found in the message.
61+
*/
62+
public function hasHeader($header);
63+
64+
/**
65+
* Retrieve a header by the given case-insensitive name as a string.
66+
*
67+
* This method returns all of the header values of the given
68+
* case-insensitive header name as a string concatenated together using
69+
* a comma.
70+
*
71+
* @param string $header Case-insensitive header name.
72+
*
73+
* @return string
74+
*/
75+
public function getHeader($header);
76+
77+
/**
78+
* Retrieve a header by the given case-insensitive name as an array of
79+
* strings.
80+
*
81+
* @param string $header Case-insensitive header name.
82+
*
83+
* @return array
84+
*/
85+
public function getHeaderAsArray($header);
86+
87+
/**
88+
* Sets a header, replacing any existing values of any headers with the
89+
* same case-insensitive name.
90+
*
91+
* The header values MUST be a string or an array of strings.
92+
*
93+
* @param string $header Header name
94+
* @param string|array $value Header value(s)
95+
*
96+
* @return self Returns the message.
97+
*/
98+
public function setHeader($header, $value);
99+
100+
/**
101+
* Sets headers, replacing any headers that have already been set on the
102+
* message.
103+
*
104+
* The array keys MUST be a string. The array values must be either a
105+
* string or an array of strings.
106+
*
107+
* @param array $headers Headers to set.
108+
*
109+
* @return self Returns the message.
110+
*/
111+
public function setHeaders(array $headers);
112+
113+
/**
114+
* Appends a header value to any existing values associated with the
115+
* given header name.
116+
*
117+
* @param string $header Header name to add
118+
* @param string $value Value of the header
119+
*
120+
* @return self
121+
*/
122+
public function addHeader($header, $value);
123+
124+
/**
125+
* Merges in an associative array of headers.
126+
*
127+
* Each array key MUST be a string representing the case-insensitive name
128+
* of a header. Each value MUST be either a string or an array of strings.
129+
* For each value, the value is appended to any existing header of the same
130+
* name, or, if a header does not already exist by the given name, then the
131+
* header is added.
132+
*
133+
* @param array $headers Associative array of headers to add to the message
134+
*
135+
* @return self
136+
*/
137+
public function addHeaders(array $headers);
138+
139+
/**
140+
* Remove a specific header by case-insensitive name.
141+
*
142+
* @param string $header HTTP header to remove
143+
*
144+
* @return self
145+
*/
146+
public function removeHeader($header);
147+
}

src/RequestInterface.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Psr\HttpMessage;
4+
5+
/**
6+
* A HTTP request message.
7+
* @link http://tools.ietf.org/html/rfc2616#section-5
8+
*/
9+
interface RequestInterface extends MessageInterface
10+
{
11+
/**
12+
* Gets the HTTP method of the request.
13+
*
14+
* @return string Returns the request method.
15+
*/
16+
public function getMethod();
17+
18+
/**
19+
* Sets the method to be performed on the resource identified by the
20+
* Request-URI.
21+
*
22+
* While HTTP method names are typically all uppercase characters, HTTP
23+
* method names are case-sensitive and thus implementations SHOULD NOT
24+
* modify the given string.
25+
*
26+
* @param string $method Case-insensitive method.
27+
*
28+
* @return self Returns the request.
29+
*/
30+
public function setMethod($method);
31+
32+
/**
33+
* Gets the absolute request URL.
34+
*
35+
* @return string Returns the URL as a string.
36+
*/
37+
public function getUrl();
38+
39+
/**
40+
* Sets the request URL.
41+
*
42+
* The URL MUST be a string, or an object that implements the
43+
* `__toString()` method. The URL must be an absolute URI as specified
44+
* in RFC 3986.
45+
*
46+
* @param string $url Request URL.
47+
*
48+
* @return self Reference to the request.
49+
* @throws \InvalidArgumentException If the URL is invalid.
50+
* @link http://tools.ietf.org/html/rfc3986#section-4.3
51+
*/
52+
public function setUrl($url);
53+
}

src/ResponseInterface.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Psr\HttpMessage;
4+
5+
/**
6+
* A HTTP response message.
7+
* @link http://tools.ietf.org/html/rfc2616#section-6
8+
*/
9+
interface ResponseInterface extends MessageInterface
10+
{
11+
/**
12+
* Gets the response Status-Code, a 3-digit integer result code of the
13+
* server's attempt to understand and satisfy the request.
14+
*
15+
* @return integer Status code.
16+
*/
17+
public function getStatusCode();
18+
19+
/**
20+
* Gets the response Reason-Phrase, a short textual description of the
21+
* Status-Code.
22+
*
23+
* Because a Reason-Phrase is not a required element in response
24+
* Status-Line, the Reason-Phrase value MAY be null. Implementations MAY
25+
* choose to return the default RFC 2616 recommended reason phrase for the
26+
* response's Status-Code.
27+
*
28+
* @return string|null Reason phrase, or null if unknown.
29+
*/
30+
public function getReasonPhrase();
31+
}

0 commit comments

Comments
 (0)