Usage

Converting a PSR-7 ServerRequestInterface to a Zend\Http\PhpEnvironment\Request

The PSR-7 ServerRequestInterface corresponds to the zend-http PhpEnvironment\Request.

To convert from a PSR-7 instance to a zend-http instance, use Zend\Psr7Bridge\Psr7ServerRequest::toZend(). This method takes up to two arguments:

  • the ServerRequestInterface instance to convert.
  • a boolean flag indicating whether or not to do a "shallow" conversion.

Shallow conversions omit:

  • body parameters ("post" in zend-http)
  • uploaded files
  • the body content

It is useful to omit these for purposes of routing, for instance, when you may not need this more process-intensive data. By default, the $shallow flag is false, meaning a full conversion is done.

Examples

Full conversion to zend-http request

use Zend\Http\PhpEnvironment\Response;
use Zend\Psr7Bridge\Psr7ServerRequest;

// Assume $controller is a Zend\Mvc\Controller\AbstractController instance.
$result = $controller->dispatch(
    Psr7ServerRequest::toZend($request),
    new Response()
);

Shallow conversion to zend-http request

use Zend\Psr7Bridge\Psr7ServerRequest;

// Assume $router is a Zend\Router\Http\TreeRouteStack instance.
$match = $router->match(Psr7ServerRequest::toZend($request, true));

Found a mistake or want to contribute to the documentation? Edit this page on GitHub!