Add ZrlMiddleware class

This commit is contained in:
Hypolite Petovan 2020-06-13 13:16:35 -04:00
parent a402fbdf5d
commit f47f263fc3

View file

@ -0,0 +1,40 @@
<?php
namespace Friendica\Directory\Middleware;
use Friendica\Directory\Views\PhpRenderer;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
/**
* The ZRL middleware ensures the Renderer ZRL attribute is set if the query string parameter is present
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
* @package Friendica\Directory\Middleware
*/
class ZrlMiddleware
{
/**
* @var PhpRenderer
*/
private $phpRenderer;
public function __construct(PhpRenderer $phpRenderer)
{
$this->phpRenderer = $phpRenderer;
}
/**
* @param ServerRequestInterface $request PSR7 request
* @param ResponseInterface $response PSR7 response
* @param callable $next Next middleware
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$this->phpRenderer->addAttribute('zrl', $request->getQueryParams()['zrl'] ?? null);
return $next($request, $response);
}
}