This post is part of series:
- Part 1: Overview
- Part 2: Request and URI
- Part 3: Response
- Part 4: File Uploads
- Part 5: HTTP-Client
- Part 6: Server Request
- Part 7: Middleware
- Part 8: Usage in a Magento module
In Part 3 we already discovered the
RequestInterface which is used on client side. In this part, we have a more detailed look on the server side.
The Server Request inherits all methods of the
RequestInterface and has 13 additional methods. Six methods are available to setup the request object:
Like on client side we have to be careful. The Server Request is designed to be immutable (see Part 3). If we look in the code of the Guzzle\Psr7 implementation of the Server Request, we can see that all this methods are needed to create complete request from all global variables
($_SERVER, $_COOKIE, $_GET, $_POST, $_FILES) which we will get from PHP.
* Return a ServerRequest populated with superglobals:
* @return ServerRequestInterface
public static function fromGlobals()
//.... skipped code
$serverRequest = new ServerRequest($method, $uri, $headers, $body, $protocol, $_SERVER);
The other methods are to consume the same data:
So we have “setter” and matching “getter” methods.
What’s up with the “getAttributes” and “getAttribute” methods? This methods are important for the next part of our blog series. The Middleware.
– Creator of n98-magerun
– Fan of football club @wormatia
– Magento user since version 0.8 beta
– 6x certified Magento developer
– PHP Top 1.000 developer (yes, I’m PHP4 certified and sooooo old)
– Chief development officer at netz98