PSR-7 Standard – Part 6 – Server Requests

PSR-7 Standard – Part 6 – Server Requests

This post is part of series:

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:

  • withCookieParams
  • withQueryParams
  • withUploadedFiles
  • withParsedBody
  • withAttribute
  • withoutAttribute

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.

(ServerRequestInterface on Github)

The other methods are to consume the same data:

  • getServerParams
  • getCookieParams
  • getQueryParams
  • getParsedBody
  • getAttributes
  • getAttribute

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
– 3x certified Magento developer
– PHP Top 1.000 developer (yes, I’m PHP4 certified and sooooo old)
– Chief development officer at netz98

Leave a Reply

%d bloggers like this: