Developing a PSR-7 Request class
One of the key characteristics of PSR-7 middleware is the use of Request and Response classes. When applied, this enables different blocks of software to perform together without sharing any specific knowledge between them. In this context, a request class should encompass all aspects of the original user request, including such items as browser settings, the original URL requested, parameters passed, and so forth.
How to do it...
- First, be sure to define classes to represent the
Uri
,Stream
, andUploadedFile
value objects, as described in the previous recipe. - Now we are ready to define the core
Application\MiddleWare\Message
class. This class consumesStream
andUri
and implementsPsr\Http\Message\MessageInterface
. We first define properties for the key value objects, including those representing the message body (that is, aStreamInterface
instance), version, and HTTP headers:namespace Application\MiddleWare; use Psr\Http\Message\ { MessageInterface, ...