1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Xervice\Web\Business\Executor; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
8
|
|
|
use Xervice\Routing\RoutingFacade; |
9
|
|
|
use Xervice\Web\Business\Executor\ResponseHandler\ResponseHandlerInterface; |
10
|
|
|
use Xervice\Web\Business\Executor\Validator\ValidatorInterface; |
11
|
|
|
|
12
|
|
|
class ExecutionProvider implements ExecutionProviderInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var \Xervice\Routing\RoutingFacade |
16
|
|
|
*/ |
17
|
|
|
private $routeFacade; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \Xervice\Web\Business\Executor\ResponseHandler\ResponseHandlerInterface |
21
|
|
|
*/ |
22
|
|
|
private $responseHandler; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var \Xervice\Web\Business\Executor\Validator\ValidatorInterface |
26
|
|
|
*/ |
27
|
|
|
private $validator; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* ExecutionProvider constructor. |
31
|
|
|
* |
32
|
|
|
* @param \Xervice\Routing\RoutingFacade $routeFacade |
33
|
|
|
* @param \Xervice\Web\Business\Executor\ResponseHandler\ResponseHandlerInterface $responseHandler |
34
|
|
|
* @param \Xervice\Web\Business\Executor\Validator\ValidatorInterface $validator |
35
|
|
|
*/ |
36
|
2 |
|
public function __construct( |
37
|
|
|
RoutingFacade $routeFacade, |
38
|
|
|
ResponseHandlerInterface $responseHandler, |
39
|
|
|
ValidatorInterface $validator |
40
|
|
|
) { |
41
|
2 |
|
$this->routeFacade = $routeFacade; |
42
|
2 |
|
$this->responseHandler = $responseHandler; |
43
|
2 |
|
$this->validator = $validator; |
44
|
2 |
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @throws \Xervice\Web\Business\Exception\WebExeption |
49
|
|
|
*/ |
50
|
|
|
public function execute(): void |
51
|
|
|
{ |
52
|
|
|
$this->executeRequest( |
53
|
|
|
$this->getRequest() |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $url |
59
|
|
|
* |
60
|
|
|
* @throws \Xervice\Web\Business\Exception\WebExeption |
61
|
|
|
*/ |
62
|
2 |
|
public function executeUrl(string $url): void |
63
|
|
|
{ |
64
|
2 |
|
$this->handleData( |
65
|
2 |
|
$this->routeFacade->matchUrl($url) |
66
|
|
|
); |
67
|
2 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
71
|
|
|
* |
72
|
|
|
* @throws \Xervice\Web\Business\Exception\WebExeption |
73
|
|
|
*/ |
74
|
|
|
public function executeRequest(Request $request): void |
75
|
|
|
{ |
76
|
|
|
$this->handleData( |
77
|
|
|
$this->routeFacade->matchRequest($request) |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return \Symfony\Component\HttpFoundation\Request |
83
|
|
|
*/ |
84
|
|
|
private function getRequest(): Request |
85
|
|
|
{ |
86
|
|
|
return Request::createFromGlobals(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param $executionData |
91
|
|
|
* |
92
|
|
|
* @throws \Xervice\Web\Business\Exception\WebExeption |
93
|
|
|
*/ |
94
|
2 |
|
private function handleData($executionData): void |
95
|
|
|
{ |
96
|
2 |
|
$this->validator->validateExecutionData($executionData); |
97
|
2 |
|
$this->responseHandler->handleResponse($executionData); |
98
|
|
|
} |
99
|
|
|
} |