2020-10-19 20:18:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Alltube;
|
|
|
|
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
use Slim\Http\Request;
|
|
|
|
use Slim\Http\Response;
|
|
|
|
use Slim\Router;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RouterPathMiddleware
|
|
|
|
* @package Alltube
|
|
|
|
*/
|
|
|
|
class RouterPathMiddleware
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Router
|
|
|
|
*/
|
|
|
|
private $router;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RouterPathMiddleware constructor.
|
|
|
|
* @param ContainerInterface $container
|
|
|
|
*/
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
$this->router = $container->get('router');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
* @param Response $response
|
|
|
|
* @param callable $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __invoke(Request $request, Response $response, callable $next)
|
|
|
|
{
|
2020-10-19 20:20:19 +00:00
|
|
|
if ($path = current($request->getHeader('X-Forwarded-Path'))) {
|
|
|
|
$this->router->setBasePath($path);
|
|
|
|
}
|
2020-10-19 20:18:03 +00:00
|
|
|
|
|
|
|
return $next($request, $response);
|
|
|
|
}
|
|
|
|
}
|