-
Notifications
You must be signed in to change notification settings - Fork 5
/
JsonApiFactory.php
64 lines (58 loc) · 1.67 KB
/
JsonApiFactory.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
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace QP\WoohoolabsYinBundle\Factory;
use Psr\Http\Message\ResponseFactoryInterface;
use QP\WoohoolabsYinBundle\Request\Request as JsonApiRequest;
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface;
use WoohooLabs\Yin\JsonApi\JsonApi;
/**
* @author Quentin <quentin.pautrat@gmail.com>
*
* Allows you to instantiate JsonApi class.
*/
class JsonApiFactory
{
/**
* @var HttpMessageFactoryInterface
*/
private $psrFactory;
/**
* @var ResponseFactoryInterface
*/
private $responseFactory;
/**
* @var ExceptionFactoryInterface
*/
private $exceptionFactory;
/**
* Constructor.
*/
public function __construct(
HttpMessageFactoryInterface $psrFactory,
ResponseFactoryInterface $responseFactory,
ExceptionFactoryInterface $exceptionFactory
) {
$this->psrFactory = $psrFactory;
$this->responseFactory = $responseFactory;
$this->exceptionFactory = $exceptionFactory;
}
/**
* Create a new instance of JsonApi by transforming a HttpFoundation Request into PSR7 Request.
*
* @return JsonApi
*/
public function create(RequestStack $requestStack)
{
$request = $this->psrFactory->createRequest($requestStack->getCurrentRequest());
$response = $this->responseFactory->createResponse();
return new JsonApi(
new JsonApiRequest(
$request,
$this->exceptionFactory
),
$response,
$this->exceptionFactory
);
}
}