1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Xervice\Web\Business\Executor; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Xervice\Routing\RoutingFacade; |
8
|
|
|
use Xervice\Web\Business\Exception\WebExeption; |
9
|
|
|
use Xervice\Web\Business\Executor\ResponseHandler\ResponseHandlerInterface; |
10
|
|
|
|
11
|
|
|
class ExecutionProvider implements ExecutionProviderInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var \Xervice\Routing\RoutingFacade |
15
|
|
|
*/ |
16
|
|
|
private $routeFacade; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Xervice\Web\Business\Executor\ResponseHandler\ResponseHandlerInterface |
20
|
|
|
*/ |
21
|
|
|
private $responseHandler; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* ExecutionProvider constructor. |
25
|
|
|
* |
26
|
|
|
* @param \Xervice\Routing\RoutingFacade $routeFacade |
27
|
|
|
* @param \Xervice\Web\Business\Executor\ResponseHandler\ResponseHandlerInterface $responseHandler |
28
|
|
|
*/ |
29
|
2 |
|
public function __construct( |
30
|
|
|
RoutingFacade $routeFacade, |
31
|
|
|
ResponseHandlerInterface $responseHandler |
32
|
|
|
) { |
33
|
2 |
|
$this->routeFacade = $routeFacade; |
34
|
2 |
|
$this->responseHandler = $responseHandler; |
35
|
2 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @throws \Xervice\Web\Business\Exception\WebExeption |
39
|
|
|
*/ |
40
|
|
|
public function execute(): void |
41
|
|
|
{ |
42
|
|
|
$this->executeUrl( |
43
|
|
|
sprintf( |
44
|
|
|
'/%s', |
45
|
|
|
$_SERVER['REQUEST_URI'] |
46
|
|
|
) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $url |
52
|
|
|
* |
53
|
|
|
* @throws \Xervice\Web\Business\Exception\WebExeption |
54
|
|
|
*/ |
55
|
2 |
|
public function executeUrl(string $url): void |
56
|
|
|
{ |
57
|
2 |
|
$executionData = $this->routeFacade->matchUrl($url); |
58
|
2 |
|
$this->validateExecutionData($executionData); |
59
|
2 |
|
$this->responseHandler->handleResponse($executionData); |
60
|
2 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param array $executionData |
64
|
|
|
* |
65
|
|
|
* @throws \Xervice\Web\Business\Exception\WebExeption |
66
|
|
|
*/ |
67
|
2 |
|
private function validateExecutionData(array $executionData): void |
68
|
|
|
{ |
69
|
2 |
|
if (!isset($executionData['_controller'])) { |
70
|
|
|
throw new WebExeption( |
71
|
|
|
sprintf( |
72
|
|
|
'No callable given for route %s', |
73
|
|
|
$executionData['_route'] |
74
|
|
|
) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |