Skip to content

Commit

Permalink
Merge pull request #16 from weierophinney/feature/immutability
Browse files Browse the repository at this point in the history
Immutability + URI interface
  • Loading branch information
Paul M. Jones committed Jan 18, 2015
2 parents 18619ee + 2721ad1 commit 70d7c44
Show file tree
Hide file tree
Showing 10 changed files with 812 additions and 478 deletions.
171 changes: 0 additions & 171 deletions src/IncomingRequestInterface.php

This file was deleted.

45 changes: 0 additions & 45 deletions src/IncomingResponseInterface.php

This file was deleted.

100 changes: 93 additions & 7 deletions src/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
* 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 a new instance that contains the changed state.
*
* @link http://www.ietf.org/rfc/rfc7230.txt
* @link http://www.ietf.org/rfc/rfc7231.txt
*/
interface MessageInterface
{
/**
* Gets the HTTP protocol version as a string.
* Retrieves the HTTP protocol version as a string.
*
* The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
*
Expand All @@ -22,14 +26,22 @@ interface MessageInterface
public function getProtocolVersion();

/**
* Gets the body of the message.
* Create a new instance with the specified HTTP protocol version.
*
* The version string MUST contain only the HTTP version number (e.g.,
* "1.1", "1.0").
*
* @return StreamableInterface|null Returns the body, or null if not set.
* 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 protocol version.
*
* @param string $version HTTP protocol version
* @return self
*/
public function getBody();
public function withProtocolVersion($version);

/**
* Gets all message headers.
* Retrieves all message headers.
*
* 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.
Expand Down Expand Up @@ -69,7 +81,8 @@ public function hasHeader($header);
* a comma.
*
* NOTE: Not all header values may be appropriately represented using
* comma concatenation.
* comma concatenation. For such headers, use getHeaderLines() instead
* and supply your own delimiter when concatenating.
*
* @param string $header Case-insensitive header name.
* @return string
Expand All @@ -82,5 +95,78 @@ public function getHeader($header);
* @param string $header Case-insensitive header name.
* @return string[]
*/
public function getHeaderAsArray($header);
public function getHeaderLines($header);

/**
* Create a new instance with the provided header, replacing any existing
* values of any headers with the same case-insensitive name.
*
* The header name is case-insensitive. The header values MUST be a string
* or an array of strings.
*
* 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 and/or updated header and value.
*
* @param string $header Header name
* @param string|string[] $value Header value(s).
* @return self
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withHeader($header, $value);

/**
* Creates a new 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 a new instance that has the
* new header and/or value.
*
* @param string $header Header name to add
* @param string|string[] $value Header value(s).
* @return self
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withAddedHeader($header, $value);

/**
* Creates a new 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 a new instance that removes
* the named header.
*
* @param string $header HTTP header to remove
* @return self
*/
public function withoutHeader($header);

/**
* Gets the body of the message.
*
* @return StreamableInterface Returns the body as a stream.
*/
public function getBody();

/**
* Create a new 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);
}
Loading

0 comments on commit 70d7c44

Please sign in to comment.