rfc:http-interface
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:http-interface [2014/10/30 18:06] – created googleguy | rfc:http-interface [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Standardized PHP Http Interface ====== | ====== PHP RFC: Standardized PHP Http Interface ====== | ||
- | * Version: 0.1 | + | * Version: 0.2 |
* Date: 2014-10-30 | * Date: 2014-10-30 | ||
* Author: Sherif Ramadan, googleguy@php.net | * Author: Sherif Ramadan, googleguy@php.net | ||
Line 9: | Line 9: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | This RFC proposes creating | + | This RFC proposes creating |
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes creating | + | This RFC proposes creating |
The ultimate goal of this proposal is to make HTTP message handling in PHP ubiquitous and conforming. Superglobal variables such as $_POST and $_GET are great, but they do not address many of the concerns that current web users are dealing with today such as RESTful APIs. Some RESTful APIs might rely on PUT and DELETE HTTP verbs (methods) to handle certain requests and PHP does not make dealing with such requests intuitive. So some users requested $_PUT and $_DELETE superglobals to be added to the list. However, this RFC does not propose such features. Instead, it is proposed to rid PHP of the super global variables entirely and make HTTP message processing a standard interface that can be implement by the user in any way they deem fit. | The ultimate goal of this proposal is to make HTTP message handling in PHP ubiquitous and conforming. Superglobal variables such as $_POST and $_GET are great, but they do not address many of the concerns that current web users are dealing with today such as RESTful APIs. Some RESTful APIs might rely on PUT and DELETE HTTP verbs (methods) to handle certain requests and PHP does not make dealing with such requests intuitive. So some users requested $_PUT and $_DELETE superglobals to be added to the list. However, this RFC does not propose such features. Instead, it is proposed to rid PHP of the super global variables entirely and make HTTP message processing a standard interface that can be implement by the user in any way they deem fit. | ||
- | 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. | + | 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. |
+ | |||
+ | ===== 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 | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Implementation ===== | ||
+ | |||
+ | It appears the SAPI_API to the incoming HTTP request to PHP is already capable of allowing things such as register callbacks for the header, setting different content_type handlers/ | ||
+ | |||
+ | * http:// | ||
+ | * http:// | ||
+ | |||
+ | |||
+ | This can be easily achieved by providing a direct interface to the internal API through a new class that will then be called along with the SAPI API on RINIT stage. | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | Superglobal | + | The default base class for HttpRequest will implement the existing behavior by populating GPC variables |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 50: | Line 150: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Language | + | Not a language |
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | |||
- | |||
- | ===== Implementation ===== | ||
===== 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