Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (39 sloc) 1.38 KB
<?php
/**
* @see https://github.com/zendframework/zend-expressive-helpers for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-helpers/blob/master/LICENSE.md New BSD License
*/
declare(strict_types=1);
namespace Zend\Expressive\Helper;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Expressive\Router\RouteResult;
/**
* Pipeline middleware for injecting a UrlHelper with a RouteResult.
*/
class UrlHelperMiddleware implements MiddlewareInterface
{
/**
* @var UrlHelper
*/
private $helper;
public function __construct(UrlHelper $helper)
{
$this->helper = $helper;
}
/**
* Inject the UrlHelper instance with a RouteResult, if present as a request attribute.
* Injects the helper, and then dispatches the next middleware.
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
{
$result = $request->getAttribute(RouteResult::class, false);
if ($result instanceof RouteResult) {
$this->helper->setRouteResult($result);
}
return $handler->handle($request);
}
}
You can’t perform that action at this time.