Update based on changes to PSR-7

This commit is contained in:
PJ Dietz 2015-04-15 19:34:33 -04:00
parent 4a75f4e3a6
commit 6b20d1ea96
16 changed files with 127 additions and 1183 deletions

View File

@ -12,15 +12,15 @@
} }
], ],
"require": { "require": {
"php": ">=5.4.0" "php": ">=5.4.0",
"psr/http-message": "dev-master"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.5" "phpunit/phpunit": "4.5.x"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"WellRESTed\\" : "src/", "WellRESTed\\" : "src/"
"Psr\\Http\\Message\\": "srcPsr/"
}, },
"classmap": ["src/HttpExceptions.php"] "classmap": ["src/HttpExceptions.php"]
} }

95
composer.lock generated
View File

@ -4,8 +4,55 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "f932f69dafff860d85b46ee774dd8aa2", "hash": "825703713a0e0eab25f1de28f7cc1c33",
"packages": [], "packages": [
{
"name": "psr/http-message",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "9723465b3e7c8ecb0436f066bfb8a13e1bac1789"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/9723465b3e7c8ecb0436f066bfb8a13e1bac1789",
"reference": "9723465b3e7c8ecb0436f066bfb8a13e1bac1789",
"shasum": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2015-04-13 14:20:01"
}
],
"packages-dev": [ "packages-dev": [
{ {
"name": "doctrine/instantiator", "name": "doctrine/instantiator",
@ -234,33 +281,31 @@
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
"version": "1.4.0", "version": "1.3.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb",
"reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.3" "php": ">=5.3.3"
}, },
"type": "library", "type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": { "autoload": {
"classmap": [ "classmap": [
"src/" "File/"
] ]
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [ "license": [
"BSD-3-Clause" "BSD-3-Clause"
], ],
@ -277,7 +322,7 @@
"filesystem", "filesystem",
"iterator" "iterator"
], ],
"time": "2015-04-02 05:19:05" "time": "2013-10-10 15:34:57"
}, },
{ {
"name": "phpunit/php-text-template", "name": "phpunit/php-text-template",
@ -418,16 +463,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "4.6.4", "version": "4.5.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "163232991e652e6efed2f8470326fffa61e848e2" "reference": "d6429b0995b24a2d9dfe5587ee3a7071c1161af4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/163232991e652e6efed2f8470326fffa61e848e2", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d6429b0995b24a2d9dfe5587ee3a7071c1161af4",
"reference": "163232991e652e6efed2f8470326fffa61e848e2", "reference": "d6429b0995b24a2d9dfe5587ee3a7071c1161af4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -439,17 +484,17 @@
"php": ">=5.3.3", "php": ">=5.3.3",
"phpspec/prophecy": "~1.3,>=1.3.1", "phpspec/prophecy": "~1.3,>=1.3.1",
"phpunit/php-code-coverage": "~2.0,>=2.0.11", "phpunit/php-code-coverage": "~2.0,>=2.0.11",
"phpunit/php-file-iterator": "~1.4", "phpunit/php-file-iterator": "~1.3.2",
"phpunit/php-text-template": "~1.2", "phpunit/php-text-template": "~1.2",
"phpunit/php-timer": "~1.0", "phpunit/php-timer": "~1.0.2",
"phpunit/phpunit-mock-objects": "~2.3", "phpunit/phpunit-mock-objects": "~2.3",
"sebastian/comparator": "~1.1", "sebastian/comparator": "~1.1",
"sebastian/diff": "~1.2", "sebastian/diff": "~1.1",
"sebastian/environment": "~1.2", "sebastian/environment": "~1.2",
"sebastian/exporter": "~1.2", "sebastian/exporter": "~1.2",
"sebastian/global-state": "~1.0", "sebastian/global-state": "~1.0",
"sebastian/version": "~1.0", "sebastian/version": "~1.0",
"symfony/yaml": "~2.1|~3.0" "symfony/yaml": "~2.0"
}, },
"suggest": { "suggest": {
"phpunit/php-invoker": "~1.1" "phpunit/php-invoker": "~1.1"
@ -460,7 +505,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "4.6.x-dev" "dev-master": "4.5.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -486,7 +531,7 @@
"testing", "testing",
"xunit" "xunit"
], ],
"time": "2015-04-11 05:23:21" "time": "2015-03-29 09:24:05"
}, },
{ {
"name": "phpunit/phpunit-mock-objects", "name": "phpunit/phpunit-mock-objects",
@ -967,7 +1012,9 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": {
"psr/http-message": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {

View File

@ -3,14 +3,14 @@
namespace WellRESTed\Message; namespace WellRESTed\Message;
use Psr\Http\Message\MessageInterface; use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\StreamableInterface; use Psr\Http\Message\StreamInterface;
use WellRESTed\Stream\NullStream; use WellRESTed\Stream\NullStream;
abstract class Message implements MessageInterface abstract class Message implements MessageInterface
{ {
/** @var HeaderCollection */ /** @var HeaderCollection */
protected $headers; protected $headers;
/** @var StreamableInterface */ /** @var StreamInterface */
protected $body; protected $body;
/** @var string */ /** @var string */
protected $protcolVersion = "1.1"; protected $protcolVersion = "1.1";
@ -224,7 +224,7 @@ abstract class Message implements MessageInterface
/** /**
* Gets the body of the message. * Gets the body of the message.
* *
* @return StreamableInterface Returns the body as a stream. * @return StreamInterface Returns the body as a stream.
*/ */
public function getBody() public function getBody()
{ {
@ -234,17 +234,17 @@ abstract class Message implements MessageInterface
/** /**
* Create a new instance, with the specified message body. * Create a new instance, with the specified message body.
* *
* The body MUST be a StreamableInterface object. * The body MUST be a StreamInterface object.
* *
* This method MUST be implemented in such a way as to retain the * This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return a new instance that has the * immutability of the message, and MUST return a new instance that has the
* new body stream. * new body stream.
* *
* @param StreamableInterface $body Body. * @param StreamInterface $body Body.
* @return self * @return self
* @throws \InvalidArgumentException When the body is not valid. * @throws \InvalidArgumentException When the body is not valid.
*/ */
public function withBody(StreamableInterface $body) public function withBody(StreamInterface $body)
{ {
$message = clone $this; $message = clone $this;
$message->body = $body; $message->body = $body;

View File

@ -2,8 +2,9 @@
namespace WellRESTed\Message; namespace WellRESTed\Message;
use Psr\Http\Message\An;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamableInterface; use Psr\Http\Message\StreamInterface;
use WellRESTed\Stream\Stream; use WellRESTed\Stream\Stream;
class ServerRequest extends Request implements ServerRequestInterface class ServerRequest extends Request implements ServerRequestInterface
@ -338,9 +339,9 @@ class ServerRequest extends Request implements ServerRequestInterface
/** /**
* Return a stream representing the request's body. * Return a stream representing the request's body.
* *
* Override this method to use a specific StreamableInterface implementation. * Override this method to use a specific StreamInterface implementation.
* *
* @return StreamableInterface * @return StreamInterface
*/ */
protected function getStreamForBody() protected function getStreamForBody()
{ {
@ -368,4 +369,37 @@ class ServerRequest extends Request implements ServerRequestInterface
} }
return $headers; return $headers;
} }
/**
* Retrieve normalized file upload data.
*
* This method returns upload metadata in a normalized tree, with each leaf
* an instance of Psr\Http\Message\UploadedFileInterface.
*
* These values MAY be prepared from $_FILES or the message body during
* instantiation, or MAY be injected via withUploadedFiles().
*
* @return array An array tree of UploadedFileInterface instances; an empty
* array MUST be returned if no data is present.
*/
public function getUploadedFiles()
{
// TODO: Implement getUploadedFiles() method.
}
/**
* Create a new instance with the specified uploaded files.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated body parameters.
*
* @param array An array tree of UploadedFileInterface instances.
* @return self
* @throws \InvalidArgumentException if an invalid structure is provided.
*/
public function withUploadedFiles(array $uploadedFiles)
{
// TODO: Implement withUploadedFiles() method.
}
} }

View File

@ -3,7 +3,7 @@
namespace WellRESTed\Routing; namespace WellRESTed\Routing;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamableInterface; use Psr\Http\Message\StreamInterface;
class Responder implements ResponderInterface class Responder implements ResponderInterface
{ {
@ -53,7 +53,7 @@ class Responder implements ResponderInterface
} }
} }
private function outputBody(StreamableInterface $body) private function outputBody(StreamInterface $body)
{ {
if ($this->chunkSize > 0) { if ($this->chunkSize > 0) {
$body->rewind(); $body->rewind();

View File

@ -2,9 +2,9 @@
namespace WellRESTed\Stream; namespace WellRESTed\Stream;
use Psr\Http\Message\StreamableInterface; use Psr\Http\Message\StreamInterface;
class NullStream implements StreamableInterface class NullStream implements StreamInterface
{ {
/** /**
* Reads all data from the stream into a string, from the beginning to end. * Reads all data from the stream into a string, from the beginning to end.

View File

@ -2,9 +2,9 @@
namespace WellRESTed\Stream; namespace WellRESTed\Stream;
use Psr\Http\Message\StreamableInterface; use Psr\Http\Message\StreamInterface;
class Stream implements StreamableInterface class Stream implements StreamInterface
{ {
/** @var resource */ /** @var resource */
private $resource; private $resource;

View File

@ -1,190 +0,0 @@
<?php
namespace Psr\Http\Message;
/**
* HTTP messages consist of requests from a client to a server and responses
* from a server to a client. This interface defines the methods common to
* each.
*
* Messages are considered immutable; all methods that might change state MUST
* be implemented such that they retain the internal state of the current
* message and return an instance that contains the changed state.
*
* @link http://www.ietf.org/rfc/rfc7230.txt
* @link http://www.ietf.org/rfc/rfc7231.txt
*/
interface MessageInterface
{
/**
* Retrieves the HTTP protocol version as a string.
*
* The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
*
* @return string HTTP protocol version.
*/
public function getProtocolVersion();
/**
* Return an instance with the specified HTTP protocol version.
*
* The version string MUST contain only the HTTP version number (e.g.,
* "1.1", "1.0").
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new protocol version.
*
* @param string $version HTTP protocol version
* @return self
*/
public function withProtocolVersion($version);
/**
* Retrieves all message header values.
*
* The keys represent the header name as it will be sent over the wire, and
* each value is an array of strings associated with the header.
*
* // Represent the headers as a string
* foreach ($message->getHeaders() as $name => $values) {
* echo $name . ": " . implode(", ", $values);
* }
*
* // Emit headers iteratively:
* foreach ($message->getHeaders() as $name => $values) {
* foreach ($values as $value) {
* header(sprintf('%s: %s', $name, $value), false);
* }
* }
*
* While header names are not case-sensitive, getHeaders() will preserve the
* exact case in which headers were originally specified.
*
* @return array Returns an associative array of the message's headers. Each
* key MUST be a header name, and each value MUST be an array of strings
* for that header.
*/
public function getHeaders();
/**
* Checks if a header exists by the given case-insensitive name.
*
* @param string $name Case-insensitive header field name.
* @return bool Returns true if any header names match the given header
* name using a case-insensitive string comparison. Returns false if
* no matching header name is found in the message.
*/
public function hasHeader($name);
/**
* Retrieves a message header value by the given case-insensitive name.
*
* This method returns an array of all the header values of the given
* case-insensitive header name.
*
* If the header does not appear in the message, this method MUST return an
* empty array.
*
* @param string $name Case-insensitive header field name.
* @return string[] An array of string values as provided for the given
* header. If the header does not appear in the message, this method MUST
* return an empty array.
*/
public function getHeader($name);
/**
* Retrieves the line for a single header, with the header values as a
* comma-separated string.
*
* This method returns all of the header values of the given
* case-insensitive header name as a string concatenated together using
* a comma.
*
* NOTE: Not all header values may be appropriately represented using
* comma concatenation. For such headers, use getHeader() instead
* and supply your own delimiter when concatenating.
*
* If the header does not appear in the message, this method MUST return
* a null value.
*
* @param string $name Case-insensitive header field name.
* @return string|null A string of values as provided for the given header
* concatenated together using a comma. If the header does not appear in
* the message, this method MUST return a null value.
*/
public function getHeaderLine($name);
/**
* Return an instance with the provided header, replacing any existing
* values of any headers with the same case-insensitive name.
*
* While header names are case-insensitive, the casing of the header will
* be preserved by this function, and returned from getHeaders().
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new and/or updated header and value.
*
* @param string $name Case-insensitive header field name.
* @param string|string[] $value Header value(s).
* @return self
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withHeader($name, $value);
/**
* Return an instance with the specified header appended with the
* given value.
*
* Existing values for the specified header will be maintained. The new
* value(s) will be appended to the existing list. If the header did not
* exist previously, it will be added.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new header and/or value.
*
* @param string $name Case-insensitive header field name to add.
* @param string|string[] $value Header value(s).
* @return self
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withAddedHeader($name, $value);
/**
* Return an instance without the specified header.
*
* Header resolution MUST be done without case-sensitivity.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that removes
* the named header.
*
* @param string $name Case-insensitive header field name to remove.
* @return self
*/
public function withoutHeader($name);
/**
* Gets the body of the message.
*
* @return StreamableInterface Returns the body as a stream.
*/
public function getBody();
/**
* Return an instance with the specified message body.
*
* The body MUST be a StreamableInterface object.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return a new instance that has the
* new body stream.
*
* @param StreamableInterface $body Body.
* @return self
* @throws \InvalidArgumentException When the body is not valid.
*/
public function withBody(StreamableInterface $body);
}

View File

@ -1,179 +0,0 @@
<?php
namespace Psr\Http\Message;
/**
* Representation of an outgoing, client-side request.
*
* Per the HTTP specification, this interface includes properties for
* each of the following:
*
* - Protocol version
* - HTTP method
* - URI
* - Headers
* - Message body
*
* Requests are considered immutable; all methods that might change state MUST
* be implemented such that they retain the internal state of the current
* message and return an instance that contains the changed state.
*/
interface RequestInterface extends MessageInterface
{
/**
* Extends MessageInterface::getHeaders() to provide request-specific
* behavior.
*
* Retrieves all message headers.
*
* This method acts exactly like MessageInterface::getHeaders(), with one
* behavioral change: if the Host header has not been previously set, the
* method MUST attempt to pull the host component of the composed URI, if
* present.
*
* @see MessageInterface::getHeaders()
* @see UriInterface::getHost()
* @return array Returns an associative array of the message's headers. Each
* key MUST be a header name, and each value MUST be an array of strings.
*/
public function getHeaders();
/**
* Extends MessageInterface::getHeader() to provide request-specific
* behavior.
*
* This method acts exactly like MessageInterface::getHeader(), with
* one behavioral change: if the Host header is requested, but has
* not been previously set, the method MUST attempt to pull the host
* component of the composed URI, if present.
*
* @see MessageInterface::getHeader()
* @see UriInterface::getHost()
* @param string $name Case-insensitive header field name.
* @return string[] An array of string values as provided for the given
* header. If the header does not appear in the message, this method MUST
* return an empty array.
*/
public function getHeader($name);
/**
* Extends MessageInterface::getHeaderLines() to provide request-specific
* behavior.
*
* This method returns all of the header values of the given
* case-insensitive header name as a string concatenated together using
* a comma.
*
* This method acts exactly like MessageInterface::getHeaderLines(), with
* one behavioral change: if the Host header is requested, but has
* not been previously set, the method MUST attempt to pull the host
* component of the composed URI, if present.
*
* @see MessageInterface::getHeaderLine()
* @see UriInterface::getHost()
* @param string $name Case-insensitive header field name.
* @return string|null A string of values as provided for the given header
* concatenated together using a comma. If the header does not appear in
* the message, this method MUST return a null value.
*/
public function getHeaderLine($name);
/**
* Retrieves the message's request target.
*
* Retrieves the message's request-target either as it will appear (for
* clients), as it appeared at request (for servers), or as it was
* specified for the instance (see withRequestTarget()).
*
* In most cases, this will be the origin-form of the composed URI,
* unless a value was provided to the concrete implementation (see
* withRequestTarget() below).
*
* If no URI is available, and no request-target has been specifically
* provided, this method MUST return the string "/".
*
* @return string
*/
public function getRequestTarget();
/**
* Return an instance with the specific request-target.
*
* If the request needs a non-origin-form request-target e.g., for
* specifying an absolute-form, authority-form, or asterisk-form
* this method may be used to create an instance with the specified
* request-target, verbatim.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* changed request target.
*
* @link http://tools.ietf.org/html/rfc7230#section-2.7 (for the various
* request-target forms allowed in request messages)
* @param mixed $requestTarget
* @return self
*/
public function withRequestTarget($requestTarget);
/**
* Retrieves the HTTP method of the request.
*
* @return string Returns the request method.
*/
public function getMethod();
/**
* Return an instance with the provided HTTP method.
*
* While HTTP method names are typically all uppercase characters, HTTP
* method names are case-sensitive and thus implementations SHOULD NOT
* modify the given string.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* changed request method.
*
* @param string $method Case-insensitive method.
* @return self
* @throws \InvalidArgumentException for invalid HTTP methods.
*/
public function withMethod($method);
/**
* Retrieves the URI instance.
*
* This method MUST return a UriInterface instance.
*
* @link http://tools.ietf.org/html/rfc3986#section-4.3
* @return UriInterface Returns a UriInterface instance
* representing the URI of the request, if any.
*/
public function getUri();
/**
* Returns an instance with the provided URI.
*
* This method will update the Host header of the returned request by
* default if the URI contains a host component. If the URI does not
* contain a host component, any pre-existing Host header will be carried
* over to the returned request.
*
* You can opt-in to preserving the original state of the Host header by
* setting `$preserveHost` to `true`. When `$preserveHost` is set to
* `true`, the returned request will not update the Host header of the
* returned message -- even if the message contains no Host header. This
* means that a call to `getHeader('Host')` on the original request MUST
* equal the return value of a call to `getHeader('Host')` on the returned
* request.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new UriInterface instance.
*
* @link http://tools.ietf.org/html/rfc3986#section-4.3
* @param UriInterface $uri New request URI to use.
* @param bool $preserveHost Preserve the original state of the Host header.
* @return self
*/
public function withUri(UriInterface $uri, $preserveHost = false);
}

View File

@ -1,70 +0,0 @@
<?php
namespace Psr\Http\Message;
/**
* Representation of an outgoing, server-side response.
*
* Per the HTTP specification, this interface includes properties for
* each of the following:
*
* - Protocol version
* - Status code and reason phrase
* - Headers
* - Message body
*
* Responses are considered immutable; all methods that might change state MUST
* be implemented such that they retain the internal state of the current
* message and return an instance that contains the changed state.
*/
interface ResponseInterface extends MessageInterface
{
/**
* Gets the response status code.
*
* The status code is a 3-digit integer result code of the server's attempt
* to understand and satisfy the request.
*
* @return int Status code.
*/
public function getStatusCode();
/**
* Return an instance with the specified status code, and optionally
* reason phrase, for the response.
*
* If no reason phrase is specified, implementations MAY choose to default
* to the RFC 7231 or IANA recommended reason phrase for the response's
* status code.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated status and reason phrase.
*
* @link http://tools.ietf.org/html/rfc7231#section-6
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
* @param int $code The 3-digit integer result code to set.
* @param null|string $reasonPhrase The reason phrase to use with the
* provided status code; if none is provided, implementations MAY
* use the defaults as suggested in the HTTP specification.
* @return self
* @throws \InvalidArgumentException For invalid status code arguments.
*/
public function withStatus($code, $reasonPhrase = null);
/**
* Gets the response reason phrase, a short textual description of the
* status code.
*
* Because a reason phrase is not a required element in a response
* status line, the reason phrase value MAY be null. Implementations MAY
* choose to return the default RFC 7231 recommended reason phrase (or those
* listed in the IANA HTTP Status Code Registry) for the response's
* status code.
*
* @link http://tools.ietf.org/html/rfc7231#section-6
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
* @return string|null Reason phrase, or null if unknown.
*/
public function getReasonPhrase();
}

View File

@ -1,244 +0,0 @@
<?php
namespace Psr\Http\Message;
/**
* Representation of an incoming, server-side HTTP request.
*
* Per the HTTP specification, this interface includes properties for
* each of the following:
*
* - Protocol version
* - HTTP method
* - URI
* - Headers
* - Message body
*
* Additionally, it encapsulates all data as it has arrived to the
* application from the CGI and/or PHP environment, including:
*
* - The values represented in $_SERVER.
* - Any cookies provided (generally via $_COOKIE)
* - Query string arguments (generally via $_GET, or as parsed via parse_str())
* - Upload files, if any (as represented by $_FILES)
* - Deserialized body parameters (generally from $_POST)
*
* $_SERVER and $_FILES values MUST be treated as immutable, as they represent
* application state at the time of request; as such, no methods are provided
* to allow modification of those values. The other values provide such methods,
* as they can be restored from $_SERVER, $_FILES, or the request body, and may
* need treatment during the application (e.g., body parameters may be
* deserialized based on content type).
*
* Additionally, this interface recognizes the utility of introspecting a
* request to derive and match additional parameters (e.g., via URI path
* matching, decrypting cookie values, deserializing non-form-encoded body
* content, matching authorization headers to users, etc). These parameters
* are stored in an "attributes" property.
*
* Requests are considered immutable; all methods that might change state MUST
* be implemented such that they retain the internal state of the current
* message and return an instance that contains the changed state.
*/
interface ServerRequestInterface extends RequestInterface
{
/**
* Retrieve server parameters.
*
* Retrieves data related to the incoming request environment,
* typically derived from PHP's $_SERVER superglobal. The data IS NOT
* REQUIRED to originate from $_SERVER.
*
* @return array
*/
public function getServerParams();
/**
* Retrieve cookies.
*
* Retrieves cookies sent by the client to the server.
*
* The data MUST be compatible with the structure of the $_COOKIE
* superglobal.
*
* @return array
*/
public function getCookieParams();
/**
* Return an instance with the specified cookies.
*
* The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST
* be compatible with the structure of $_COOKIE. Typically, this data will
* be injected at instantiation.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated cookie values.
*
* @param array $cookies Array of key/value pairs representing cookies.
* @return self
*/
public function withCookieParams(array $cookies);
/**
* Retrieve query string arguments.
*
* Retrieves the deserialized query string arguments, if any.
*
* Note: the query params might not be in sync with the URI or server
* params. If you need to ensure you are only getting the original
* values, you may need to parse the query string from `getUri()->getQuery()`
* or from the `QUERY_STRING` server param.
*
* @return array
*/
public function getQueryParams();
/**
* Return an instance with the specified query string arguments.
*
* These values SHOULD remain immutable over the course of the incoming
* request. They MAY be injected during instantiation, such as from PHP's
* $_GET superglobal, or MAY be derived from some other value such as the
* URI. In cases where the arguments are parsed from the URI, the data
* MUST be compatible with what PHP's parse_str() would return for
* purposes of how duplicate query parameters are handled, and how nested
* sets are handled.
*
* Setting query string arguments MUST NOT change the URI stored by the
* request, nor the values in the server params.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated query string arguments.
*
* @param array $query Array of query string arguments, typically from
* $_GET.
* @return self
*/
public function withQueryParams(array $query);
/**
* Retrieve the upload file metadata.
*
* This method MUST return file upload metadata in the same structure
* as PHP's $_FILES superglobal.
*
* These values MUST remain immutable over the course of the incoming
* request. They SHOULD be injected during instantiation, such as from PHP's
* $_FILES superglobal, but MAY be derived from other sources.
*
* @return array Upload file(s) metadata, if any.
*/
public function getFileParams();
/**
* Retrieve any parameters provided in the request body.
*
* If the request Content-Type is either application/x-www-form-urlencoded
* or multipart/form-data, and the request method is POST, this method MUST
* return the contents of $_POST.
*
* Otherwise, this method may return any results of deserializing
* the request body content; as parsing returns structured content, the
* potential types MUST be arrays or objects only. A null value indicates
* the absence of body content.
*
* @return null|array|object The deserialized body parameters, if any.
* These will typically be an array or object.
*/
public function getParsedBody();
/**
* Return an instance with the specified body parameters.
*
* These MAY be injected during instantiation.
*
* If the request Content-Type is either application/x-www-form-urlencoded
* or multipart/form-data, and the request method is POST, use this method
* ONLY to inject the contents of $_POST.
*
* The data IS NOT REQUIRED to come from $_POST, but MUST be the results of
* deserializing the request body content. Deserialization/parsing returns
* structured data, and, as such, this method ONLY accepts arrays or objects,
* or a null value if nothing was available to parse.
*
* As an example, if content negotiation determines that the request data
* is a JSON payload, this method could be used to create a request
* instance with the deserialized parameters.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated body parameters.
*
* @param null|array|object $data The deserialized body data. This will
* typically be in an array or object.
* @return self
*/
public function withParsedBody($data);
/**
* Retrieve attributes derived from the request.
*
* The request "attributes" may be used to allow injection of any
* parameters derived from the request: e.g., the results of path
* match operations; the results of decrypting cookies; the results of
* deserializing non-form-encoded message bodies; etc. Attributes
* will be application and request specific, and CAN be mutable.
*
* @return array Attributes derived from the request.
*/
public function getAttributes();
/**
* Retrieve a single derived request attribute.
*
* Retrieves a single derived request attribute as described in
* getAttributes(). If the attribute has not been previously set, returns
* the default value as provided.
*
* This method obviates the need for a hasAttribute() method, as it allows
* specifying a default value to return if the attribute is not found.
*
* @see getAttributes()
* @param string $name The attribute name.
* @param mixed $default Default value to return if the attribute does not exist.
* @return mixed
*/
public function getAttribute($name, $default = null);
/**
* Return an instance with the specified derived request attribute.
*
* This method allows setting a single derived request attribute as
* described in getAttributes().
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated attribute.
*
* @see getAttributes()
* @param string $name The attribute name.
* @param mixed $value The value of the attribute.
* @return self
*/
public function withAttribute($name, $value);
/**
* Return an instance that removes the specified derived request
* attribute.
*
* This method allows removing a single derived request attribute as
* described in getAttributes().
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that removes
* the attribute.
*
* @see getAttributes()
* @param string $name The attribute name.
* @return self
*/
public function withoutAttribute($name);
}

View File

@ -1,158 +0,0 @@
<?php
namespace Psr\Http\Message;
/**
* Describes streamable message body content.
*
* Typically, an instance will wrap a PHP stream; this interface provides
* a wrapper around the most common operations, including serialization of
* the entire stream to a string.
*/
interface StreamableInterface
{
/**
* Reads all data from the stream into a string, from the beginning to end.
*
* This method MUST attempt to seek to the beginning of the stream before
* reading data and read the stream until the end is reached.
*
* Warning: This could attempt to load a large amount of data into memory.
*
* This method MUST NOT raise an exception in order to conform with PHP's
* string casting operations.
*
* @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
* @return string
*/
public function __toString();
/**
* Closes the stream and any underlying resources.
*
* @return void
*/
public function close();
/**
* Separates any underlying resources from the stream.
*
* After the stream has been detached, the stream is in an unusable state.
*
* @return resource|null Underlying PHP stream, if any
*/
public function detach();
/**
* Get the size of the stream if known
*
* @return int|null Returns the size in bytes if known, or null if unknown.
*/
public function getSize();
/**
* Returns the current position of the file read/write pointer
*
* @return int Position of the file pointer
* @throws \RuntimeException on error.
*/
public function tell();
/**
* Returns true if the stream is at the end of the stream.
*
* @return bool
*/
public function eof();
/**
* Returns whether or not the stream is seekable.
*
* @return bool
*/
public function isSeekable();
/**
* Seek to a position in the stream.
*
* @link http://www.php.net/manual/en/function.fseek.php
* @param int $offset Stream offset
* @param int $whence Specifies how the cursor position will be calculated
* based on the seek offset. Valid values are identical to the built-in
* PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
* offset bytes SEEK_CUR: Set position to current location plus offset
* SEEK_END: Set position to end-of-stream plus offset.
* @throws \RuntimeException on failure.
*/
public function seek($offset, $whence = SEEK_SET);
/**
* Seek to the beginning of the stream.
*
* If the stream is not seekable, this method will raise an exception;
* otherwise, it will perform a seek(0).
*
* @see seek()
* @link http://www.php.net/manual/en/function.fseek.php
* @throws \RuntimeException on failure.
*/
public function rewind();
/**
* Returns whether or not the stream is writable.
*
* @return bool
*/
public function isWritable();
/**
* Write data to the stream.
*
* @param string $string The string that is to be written.
* @return int Returns the number of bytes written to the stream.
* @throws \RuntimeException on failure.
*/
public function write($string);
/**
* Returns whether or not the stream is readable.
*
* @return bool
*/
public function isReadable();
/**
* Read data from the stream.
*
* @param int $length Read up to $length bytes from the object and return
* them. Fewer than $length bytes may be returned if underlying stream
* call returns fewer bytes.
* @return string|null Returns the data read from the stream, or null if no bytes
* are available and the stream is in non-blocking mode.
* @throws \RuntimeException if an error occurs.
*/
public function read($length);
/**
* Returns the remaining contents in a string
*
* @return string
* @throws \RuntimeException if unable to read or an error occurs while
* reading.
*/
public function getContents();
/**
* Get stream metadata as an associative array or retrieve a specific key.
*
* The keys returned are identical to the keys returned from PHP's
* stream_get_meta_data() function.
*
* @link http://php.net/manual/en/function.stream-get-meta-data.php
* @param string $key Specific metadata to retrieve.
* @return array|mixed|null Returns an associative array if no key is
* provided. Returns a specific key value if a key is provided and the
* value is found, or null if the key is not found.
*/
public function getMetadata($key = null);
}

View File

@ -1,296 +0,0 @@
<?php
namespace Psr\Http\Message;
/**
* Value object representing a URI for use in HTTP requests.
*
* This interface is meant to represent only URIs for use with HTTP requests,
* and is not intended as a general-purpose URI implementation.
*
* Instances of this interface are considered immutable; all methods that
* might change state MUST be implemented such that they retain the internal
* state of the current instance and return an instance that contains the
* changed state.
*
* Typically the Host header will be also be present in the request message.
* For server-side requests, the scheme will typically be discoverable in the
* server parameters.
*
* @link http://tools.ietf.org/html/rfc3986 (the URI specification)
*/
interface UriInterface
{
/**
* Retrieve the URI scheme.
*
* Implementations SHOULD restrict values to "http", "https", or an empty
* string but MAY accommodate other schemes if required.
*
* If no scheme is present, this method MUST return an empty string.
*
* The string returned MUST omit the trailing "://" delimiter if present.
*
* @return string The scheme of the URI.
*/
public function getScheme();
/**
* Retrieve the authority portion of the URI.
*
* The authority portion of the URI is:
*
* <pre>
* [user-info@]host[:port]
* </pre>
*
* If the port component is not set or is the standard port for the current
* scheme, it SHOULD NOT be included.
*
* This method MUST return an empty string if no authority information is
* present.
*
* @return string Authority portion of the URI, in "[user-info@]host[:port]"
* format.
*/
public function getAuthority();
/**
* Retrieve the user information portion of the URI, if present.
*
* If a user is present in the URI, this will return that value;
* additionally, if the password is also present, it will be appended to the
* user value, with a colon (":") separating the values.
*
* Implementations MUST NOT return the "@" suffix when returning this value.
*
* @return string User information portion of the URI, if present, in
* "username[:password]" format.
*/
public function getUserInfo();
/**
* Retrieve the host component of the URI.
*
* This method MUST return a string; if no host component is present, an
* empty string MUST be returned.
*
* @return string Host component of the URI.
*/
public function getHost();
/**
* Retrieve the port component of the URI.
*
* If a port is present, and it is non-standard for the current scheme,
* this method MUST return it as an integer. If the port is the standard port
* used with the current scheme, this method SHOULD return null.
*
* If no port is present, and no scheme is present, this method MUST return
* a null value.
*
* If no port is present, but a scheme is present, this method MAY return
* the standard port for that scheme, but SHOULD return null.
*
* @return null|int The port for the URI.
*/
public function getPort();
/**
* Retrieve the path component of the URI.
*
* This method MUST return a string.
*
* Normally, the empty path "" and absolute path "/" are considered equal as
* defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically
* do this normalization because in contexts with a trimmed base path, e.g.
* the front controller, this difference becomes significant. It's the task
* of the user to handle both "" and "/".
*
* The value returned MUST be percent-encoded, but MUST NOT double-encode
* any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.3.
*
* As an example, if the value should include a slash ("/") not intended as
* delimiter between path segments, that value MUST be encoded (e.g., "%2F")
* when passed to the instance.
*
* @see https://tools.ietf.org/html/rfc3986#section-2
* @see https://tools.ietf.org/html/rfc3986#section-3.3
* @return string The path component of the URI.
*/
public function getPath();
/**
* Retrieve the query string of the URI.
*
* This method MUST return a string; if no query string is present, it MUST
* return an empty string.
*
* The string returned MUST omit the leading "?" character.
*
* The value returned MUST be percent-encoded, but MUST NOT double-encode
* any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.4.
*
* As an example, if a value in a key/value pair of the query string should
* include an ampersand ("&") not intended as a delimiter between values,
* that value MUST be encoded (e.g., "%26") when passed to the instance.
*
* @see https://tools.ietf.org/html/rfc3986#section-2
* @see https://tools.ietf.org/html/rfc3986#section-3.4
* @return string The URI query string.
*/
public function getQuery();
/**
* Retrieve the fragment component of the URI.
*
* This method MUST return a string; if no fragment is present, it MUST
* return an empty string.
*
* The string returned MUST omit the leading "#" character.
*
* The value returned MUST be percent-encoded, but MUST NOT double-encode
* any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.5.
*
* @see https://tools.ietf.org/html/rfc3986#section-2
* @see https://tools.ietf.org/html/rfc3986#section-3.5
* @return string The URI fragment.
*/
public function getFragment();
/**
* Return an instance with the specified scheme.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified scheme. If the scheme
* provided includes the "://" delimiter, it MUST be removed.
*
* Implementations SHOULD restrict values to "http", "https", or an empty
* string but MAY accommodate other schemes if required.
*
* An empty scheme is equivalent to removing the scheme.
*
* @param string $scheme The scheme to use with the new instance.
* @return self A new instance with the specified scheme.
* @throws \InvalidArgumentException for invalid or unsupported schemes.
*/
public function withScheme($scheme);
/**
* Return an instance with the specified user information.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified user information.
*
* Password is optional, but the user information MUST include the
* user; an empty string for the user is equivalent to removing user
* information.
*
* @param string $user User name to use for authority.
* @param null|string $password Password associated with $user.
* @return self A new instance with the specified user information.
*/
public function withUserInfo($user, $password = null);
/**
* Return an instance with the specified host.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified host.
*
* An empty host value is equivalent to removing the host.
*
* @param string $host Hostname to use with the new instance.
* @return self A new instance with the specified host.
* @throws \InvalidArgumentException for invalid hostnames.
*/
public function withHost($host);
/**
* Return an instance with the specified port.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified port.
*
* Implementations MUST raise an exception for ports outside the
* established TCP and UDP port ranges.
*
* A null value provided for the port is equivalent to removing the port
* information.
*
* @param null|int $port Port to use with the new instance; a null value
* removes the port information.
* @return self A new instance with the specified port.
* @throws \InvalidArgumentException for invalid ports.
*/
public function withPort($port);
/**
* Return an instance with the specified path.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified path.
*
* The path MUST be prefixed with "/"; if not, the implementation MAY
* provide the prefix itself.
*
* An empty path value is equivalent to removing the path.
*
* @param string $path The path to use with the new instance.
* @return self A new instance with the specified path.
* @throws \InvalidArgumentException for invalid paths.
*/
public function withPath($path);
/**
* Return an instance with the specified query string.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified query string.
*
* If the query string is prefixed by "?", that character MUST be removed.
* Additionally, the query string SHOULD be parseable by parse_str() in
* order to be valid.
*
* An empty query string value is equivalent to removing the query string.
*
* @param string $query The query string to use with the new instance.
* @return self A new instance with the specified query string.
* @throws \InvalidArgumentException for invalid query strings.
*/
public function withQuery($query);
/**
* Return an instance with the specified URI fragment.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified URI fragment.
*
* If the fragment is prefixed by "#", that character MUST be removed.
*
* An empty fragment value is equivalent to removing the fragment.
*
* @param string $fragment The URI fragment to use with the new instance.
* @return self A new instance with the specified URI fragment.
*/
public function withFragment($fragment);
/**
* Return the string representation of the URI.
*
* Concatenates the various components of the URI, using the appropriate
* delimiters:
*
* - If a scheme is present, "://" MUST append the value.
* - If the authority information is present, that value will be
* concatenated.
* - If a path is present, it MUST start with a "/" character.
* - If a query string is present, it MUST be prefixed by a "?" character.
* - If a URI fragment is present, it MUST be prefixed by a "#" character.
*
* @return string
*/
public function __toString();
}

View File

@ -238,7 +238,7 @@ class MessageTest extends \PHPUnit_Framework_TestCase
*/ */
public function testGetBodyReturnsAttachedStream() public function testGetBodyReturnsAttachedStream()
{ {
$stream = $this->prophesize('\Psr\Http\Message\StreamableInterface'); $stream = $this->prophesize('\Psr\Http\Message\StreamInterface');
$stream = $stream->reveal(); $stream = $stream->reveal();
$message = $this->getMockForAbstractClass('\WellRESTed\Message\Message'); $message = $this->getMockForAbstractClass('\WellRESTed\Message\Message');

View File

@ -110,7 +110,7 @@ class ServerRequestTest extends \PHPUnit_Framework_TestCase
public function testServerRequestProvidesBody() public function testServerRequestProvidesBody()
{ {
$body = $this->prophesize('Psr\Http\Message\StreamableInterface'); $body = $this->prophesize('Psr\Http\Message\StreamInterface');
MockServerRequestTest::$bodyStream = $body->reveal(); MockServerRequestTest::$bodyStream = $body->reveal();
$request = MockServerRequestTest::getServerRequest(); $request = MockServerRequestTest::getServerRequest();
$this->assertSame($body->reveal(), $request->getBody()); $this->assertSame($body->reveal(), $request->getBody());

View File

@ -19,7 +19,7 @@ class ResponderTest extends \PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
HeaderStack::reset(); HeaderStack::reset();
$this->body = $this->prophesize('\Psr\Http\Message\StreamableInterface'); $this->body = $this->prophesize('\Psr\Http\Message\StreamInterface');
$this->body->isReadable()->willReturn(false); $this->body->isReadable()->willReturn(false);
$this->response = $this->prophesize('\Psr\Http\Message\ResponseInterface'); $this->response = $this->prophesize('\Psr\Http\Message\ResponseInterface');
$this->response->getHeaders()->willReturn([]); $this->response->getHeaders()->willReturn([]);