Re: [PHP-DEV] Native support - PUT request, multipart form data

[email protected] (Park Framework)
Newsgroups php.internals
Message-ID <CAPRqa+HwNbU-FLYd6PHMOUHnedgW90ZqY1VpWLswtBMnB=2uww@mail.gmail.com>
As a variant, not to create a new super global variables, can be
modified $_REQUEST to OOP style

class _REQUEST  implements ArrayAccess // for backward compatibility
{
....
}

// get as array, from body request
$_REQUEST->body

// get all http request headers
$_REQUEST->headers

// get method request - POST, PUT...
$_REQUEST->method

// get Content-Type: multipart/form-data or application/json or ...
$_REQUEST->type

// get Content-Length request
$_REQUEST->length

It looks nice, but in practice it is more convenient to use an global
array - $_DATA or $_BODY or $_INPUT.

You can also do:

class _INPUT implements ArrayAccess
{

  public function get($name, $default = null) {

    if(isset($this->data[$name]) {

        return $this->data[$name];

     }
     else {
         return $default;
    }
  }

  public function filter($name, $filter = FILTER_DEFAULT, $options = null) {

       return filter_var($this->data[$name], $filter, $options);

  }
}

Examples:

$value = $_INPUT->get('varName1', 'myDefaultValue');
$email = $_INPUT->filter('varName2', FILTER_SANITIZE_EMAIL);


2014-08-17 3:25 GMT+03:00 Andrea Faulds <[email protected]>:
>
> On 17 Aug 2014, at 00:47, Park Framework <[email protected]> wrote:
>
>> Variable $_PUT is already a popular name.
>
> $_POST isn’t really POST data nor is $_GET really GET data. We shouldn’t continue this silly naming tradition given both existing names are inaccurate.
>
> We should have a query parameters array and a request body parameters array or blob.
> --
> Andrea Faulds
> http://ajf.me/
>
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.