[wp-trac] [WordPress Trac] #22325: Abstract GPCS away from the superglobals

WordPress Trac noreply at wordpress.org
Wed Oct 31 03:07:29 UTC 2012


#22325: Abstract GPCS away from the superglobals
-------------------------+-----------------------------
 Reporter:  rmccue       |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Future Release
Component:  General      |     Version:
 Severity:  minor        |  Resolution:
 Keywords:               |
-------------------------+-----------------------------

Comment (by rmccue):

 '''Symfony'''

 In Symfony, the main class for this stuff is
 [https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php
 Symfony\Component\HttpFoundation\Request]. This class is generic for all
 types of HTTP requests, including sending and receiving. When receiving,
 `Request::createFromGlobals()` is used to make a Request object from the
 superglobals. It also has a bunch of accessors for things like the host,
 host + scheme, whether it's a secure request, the request body, etc;
 basically, it abstracts all the request-related stuff.

 It uses abstraction classes called "bags" for the various arrays, such as
 [https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/HeaderBag.php
 HeaderBag] and
 [https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/ParameterBag.php
 ParameterBag]. The HeaderBag ensures that keys are lowercased before
 looking up, since headers are case-insensitive, and it also does some
 fancy parsing with cache-control headers. The ParameterBag class handles
 most other ones, and does some fancy stuff: doing `$bag->get('a[b][c]')`
 accesses `$bag->parameters['a']['b']['c']`. They ''don't'' use ArrayAccess
 though.

 '''Laravel'''

 Laravel appears to use Symfony's HttpFoundation, but with an extra
 abstraction on top of it. Overall, pretty useless.

 '''CakePHP/CodeIgniter'''

 CakePHP and CodeIgniter doesn't abstract any of the GPCS data, but Cake
 has [http://book.cakephp.org/2.0/en/core-libraries/components/request-
 handling.html some accessors] for some of the data (e.g. Accept headers,
 useragent stuff), and responding to the browser is also handled by
 responding to that.

 '''Zend Framework 2'''

 ZF2 has
 [https://github.com/zendframework/zf2/blob/master/library/Zend/Http/Request.php
 Zend\Http\Request] which does abstract everything. This has accessors
 named `getQuery()`, `getPost()`, `getCookie()`, `getFiles()`,
 `getHeaders()` and `getHeader()`. Digging into this any further had me
 banging my head against the wall, so someone else is welcome to look at
 this.

 ----

 Basically, my thoughts are that Symfony is the only one that we should
 consider looking at.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22325#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list