Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Created Request, Response, Headers, Header, and Parameters interfaces - Created README file
- Loading branch information
0 parents
commit a2e458c
Showing
6 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
PROPOSED COMMON MVC INTERFACES | ||
============================== | ||
|
||
This project is the start of a set of potential common interfaces to utilize | ||
between various frameworks. The initial goal is to agree on standard interfaces | ||
for describing Request and Response objects, as well as objects they compose. | ||
|
||
Current work is based on research Matthew Weier O'Phinney has done for the Zend | ||
Framework 2.0 MVC, as well as work currently in progress on Symfony 2 by Fabien | ||
Potencier. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Fig\Http; | ||
|
||
interface HttpHeader | ||
{ | ||
public function __construct($type, $value = null, $replace = false); | ||
|
||
/* mutators */ | ||
public function setType($type); | ||
public function setValue($type); | ||
public function replace($flag = null); // also acts as mutator | ||
|
||
/* accessors */ | ||
public function getType(); | ||
public function getValue(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Fig\Http; | ||
|
||
use Iterator, | ||
ArrayAccess, | ||
Countable; | ||
|
||
/* | ||
* In most cases, extend SplQueue, and then override where necessary | ||
*/ | ||
interface HttpHeaders extends Iterator, ArrayAccess, Countable | ||
{ | ||
/* | ||
* General mutators and accessors | ||
* | ||
* These are items that are technically part of the response headers, but | ||
* not individual headers themselves. | ||
*/ | ||
public function getProtocolVersion(); // HTTP 1.0, 1.1 | ||
public function setProtocolVersion($version); | ||
public function getStatusCode(); // 200, 301, etc. | ||
public function getStatusMessage(); | ||
public function setStatusCode($code, $text = null); | ||
|
||
/* | ||
* Adding headers | ||
* | ||
* Also: requires overriding push, unshift to ensure values are of correct | ||
* type. | ||
*/ | ||
public function addHeader(Header $header); | ||
|
||
/* | ||
* Retrieve named header; returns either a single header or an array of headers | ||
*/ | ||
public function get($type); | ||
|
||
/* Sending headers, and testing sent status */ | ||
public function send(); | ||
public function sent(); // return boolean | ||
|
||
/* Testing header status */ | ||
public function isRedirect(); | ||
|
||
/* Potential specialized mutators */ | ||
public function expire(); | ||
public function setRedirect($url, $code = 302); | ||
public function setClientTtl($seconds); | ||
public function setEtag($etag = null, $weak = false); | ||
public function setExpires($date = null); | ||
public function setLastModified($date = null); | ||
public function setMaxAge($value); | ||
public function setNotModified(); | ||
public function setPrivate($value); | ||
public function setSharedMaxAge($value); | ||
public function setTtl($seconds); | ||
public function setVary($headers, $replace = true); | ||
|
||
/* Potential specialized conditionals */ | ||
public function hasVary(); | ||
public function isCacheable(); | ||
public function isClientError(); | ||
public function isEmpty(); | ||
public function isForbidden(); | ||
public function isFresh(); | ||
public function isInformational(); | ||
public function isInvalid(); | ||
public function isNotFound(); | ||
public function isNotModified(Request $request); | ||
public function isOk(); | ||
public function isServerError(); | ||
public function isSuccessful(); | ||
public function isValidateable(); | ||
public function mustRevalidate(); | ||
|
||
/* Potential specialized accessors */ | ||
public function getAge() ; | ||
public function getContent(); | ||
public function getDate(); | ||
public function getEtag(); | ||
public function getExpires(); | ||
public function getLastModified(); | ||
public function getMaxAge(); | ||
public function getTtl(); | ||
public function getVary(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Fig\Http; | ||
|
||
interface Request | ||
{ | ||
/* mutators for various superglobals */ | ||
public function setQuery(Parameters $query); | ||
public function setPost(Parameters $post); | ||
public function setCookies(Parameters $cookies); | ||
public function setFiles(Parameters $files); // Maybe separate component for Files? | ||
public function setServer(Parameters $server); | ||
public function setEnv(Parameters $env); | ||
public function setHeaders(HttpHeaders $headers); | ||
|
||
/* accessors for various superglobals */ | ||
public function query($name = null); | ||
public function post($name = null); | ||
public function cookie($name = null); | ||
public function file($name = null); | ||
public function server($name = null); | ||
public function env($name = null); | ||
public function headers($name = null); | ||
|
||
/* URI decomposition */ | ||
public function getRequestUri(); | ||
public function getScheme(); | ||
public function getHttpHost(); | ||
public function getPort(); | ||
public function getPathInfo(); | ||
|
||
/* base path/url/script name info */ | ||
public function getBasePath(); | ||
public function getBaseUrl(); | ||
public function getScriptName(); | ||
|
||
/* capabilities */ | ||
public function getMethod(); | ||
public function setMethod($method); | ||
public function getETags(); | ||
public function getPreferredLanguage(array $locales = null); | ||
public function getLanguages(); | ||
public function getCharsets(); | ||
public function getAcceptableContentTypes(); | ||
public function isNoCache(); | ||
public function isFlashRequest(); | ||
public function isSecure(); | ||
public function isXmlHttpRequest(); | ||
|
||
/* potential method tests */ | ||
public function isDelete(); | ||
public function isGet(); | ||
public function isHead(); | ||
public function isOptions(); | ||
public function isPost(); | ||
public function isPut(); | ||
|
||
/* creational capabilities */ | ||
public function getUri(); // returns full URI string: scheme, host, port, base URL, path info, and query string | ||
public static function create($uri, $method = 'get' /** .. more args */); | ||
public function __clone(); // not sure if this needs to be in interface | ||
|
||
/* Create HTTP request */ | ||
public function __toString(); | ||
|
||
/* Create object from "document" */ | ||
public function fromString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Fig\Http; | ||
|
||
interface Response | ||
{ | ||
public function __construct($content = '', $status = 200, $headers = null); | ||
|
||
/* Create text representation of response, including protocol, status and headers */ | ||
public function __toString(); | ||
|
||
public function sendHeaders(); | ||
public function sendContent(); | ||
public function send(); // send both headers and content | ||
|
||
/* mutators and accessors */ | ||
public function getContent(); | ||
public function setContent($content); | ||
public function getHeaders(); | ||
public function setHeaders(HttpHeaders $headers); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Fig\Http; | ||
|
||
/* | ||
* Basically, an ArrayObject. You could simply define something like: | ||
* class QueryParams extends ArrayObject implements Parameters {} | ||
* and have 90% of the functionality | ||
*/ | ||
interface Parameters extends ArrayAccess, Countable, Serializable, Traversable | ||
{ | ||
public function __construct(array $values = null); | ||
|
||
/* Allow deserialization from standard array */ | ||
public function fromArray(array $values); | ||
|
||
/* Allow deserialization from raw body; e.g., for PUT requests */ | ||
public function fromString(); | ||
|
||
/* Allow serialization back to standard array */ | ||
public function toArray(); | ||
|
||
/* Allow serialization to query format; e.g., for PUT or POST requests */ | ||
public function toString(); | ||
} |