2020-10-20 21:10:14 +00:00
|
|
|
<?php
|
|
|
|
|
2020-10-20 21:13:48 +00:00
|
|
|
namespace Alltube\Middleware;
|
2020-10-20 21:10:14 +00:00
|
|
|
|
2022-02-20 12:55:44 +00:00
|
|
|
use Alltube\Factory\ViewFactory;
|
2020-10-20 21:10:14 +00:00
|
|
|
use Slim\Http\Request;
|
|
|
|
use Slim\Http\Response;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class LinkHeaderMiddleware
|
|
|
|
* @package Alltube
|
|
|
|
*/
|
|
|
|
class LinkHeaderMiddleware
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
* @param Response $response
|
|
|
|
* @param callable $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __invoke(Request $request, Response $response, callable $next)
|
|
|
|
{
|
2022-02-20 12:55:44 +00:00
|
|
|
$uri = ViewFactory::prepareUri($request);
|
|
|
|
|
2020-10-20 21:10:14 +00:00
|
|
|
$response = $response->withHeader(
|
|
|
|
'Link',
|
2021-10-19 21:14:38 +00:00
|
|
|
implode(
|
|
|
|
'; ',
|
|
|
|
[
|
2022-02-20 12:55:44 +00:00
|
|
|
'<' . $uri->getBasePath() . '/css/style.css>',
|
2021-10-19 21:14:38 +00:00
|
|
|
'rel=preload', 'as=style'
|
|
|
|
]
|
|
|
|
)
|
2020-10-20 21:10:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return $next($request, $response);
|
|
|
|
}
|
|
|
|
}
|