-
Notifications
You must be signed in to change notification settings - Fork 17
/
ApiVersion.php
53 lines (44 loc) · 1.29 KB
/
ApiVersion.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Phprest\Middleware;
use League\Container\ContainerInterface;
use Negotiation\FormatNegotiator;
use Phprest\Application;
use Phprest\HttpFoundation\Request;
use Phprest\Util;
use Symfony\Component\HttpFoundation\Request as BaseRequest;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class ApiVersion implements HttpKernelInterface
{
use Util\Mime;
protected Application $app;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* @param BaseRequest $request
* @param int $type
* @param bool $catch
*
* @return Response
*/
public function handle(BaseRequest $request, $type = self::MASTER_REQUEST, $catch = true)
{
$request = new Request($request);
$mimeProcResult = $this->processMime(
(new FormatNegotiator())->getBest($request->headers->get('Accept', '*/*'))->getValue()
);
$request->setApiVersion(
str_pad($mimeProcResult->apiVersion, 3, '.0')
);
return $this->app->handle($request, $type, $catch);
}
/**
* @return ContainerInterface
*/
public function getContainer()
{
return $this->app->getConfiguration()->getContainer();
}
}