rfc:http-interface
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:http-interface [2014/10/31 03:12] – googleguy | rfc:http-interface [2014/10/31 03:19] – googleguy | ||
---|---|---|---|
Line 17: | Line 17: | ||
This greatly reduces the need to change core PHP for any form of edge cases that may rely on processing HTTP messages differently and improves the flexibility and extensibility of PHP's built-in message processing facilities. Further more, this removes the inefficiencies of reusing/ | This greatly reduces the need to change core PHP for any form of edge cases that may rely on processing HTTP messages differently and improves the flexibility and extensibility of PHP's built-in message processing facilities. Further more, this removes the inefficiencies of reusing/ | ||
+ | |||
+ | ===== Interface Definitions ===== | ||
+ | |||
+ | The following are the interface definitions required by the implementing classes... | ||
+ | |||
+ | <code php> | ||
+ | abstract class HttpMessage | ||
+ | { | ||
+ | protected $headers = array(); | ||
+ | protected $body = ""; | ||
+ | protected $version = 1.0; | ||
+ | protected $message; | ||
+ | } | ||
+ | |||
+ | interface HttpMessageReceive | ||
+ | { | ||
+ | |||
+ | public function receiveMessage($message); | ||
+ | public function parseMessage(); | ||
+ | public function parseParameters(); | ||
+ | public function decodeBody(); | ||
+ | public function onReceive(); | ||
+ | |||
+ | } | ||
+ | |||
+ | interface HttpMessageSend | ||
+ | { | ||
+ | |||
+ | public function sendMessage($message); | ||
+ | public function composeMessage(); | ||
+ | public function encodeBody(); | ||
+ | public function onSend(); | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | So an implementing class could look something like this... | ||
+ | |||
+ | <code php> | ||
+ | class HttpRequest extends HttpMessage implements HttpMessageReceive | ||
+ | { | ||
+ | |||
+ | protected $parameters = array(); | ||
+ | protected $method, $requestURI, | ||
+ | |||
+ | public function receiveMessage($message) | ||
+ | { | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | public function parseMessage() | ||
+ | { | ||
+ | // implement message parsing here | ||
+ | list($header, | ||
+ | $this-> | ||
+ | $headers = explode(" | ||
+ | $header = array_shift($headers); | ||
+ | list($this-> | ||
+ | $this-> | ||
+ | foreach($headers as $h) { | ||
+ | list($key, $value) = explode(":", | ||
+ | if ($key === null) { | ||
+ | throw new Exception(" | ||
+ | } | ||
+ | $this-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public function parseParameters() | ||
+ | { | ||
+ | // implement parameter parsing method here | ||
+ | } | ||
+ | |||
+ | public function decodeBody() | ||
+ | { | ||
+ | // implement message body decoding here | ||
+ | } | ||
+ | |||
+ | public function onReceive() | ||
+ | { | ||
+ | // implement on receive hook here | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 59: | Line 148: | ||
===== References ===== | ===== References ===== | ||
- | https:// | + | * https:// |
- | https:// | + | |
===== Rejected Features ===== | ===== Rejected Features ===== |
rfc/http-interface.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1