1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Core\ControllerDispatcher; |
4
|
|
|
|
5
|
|
|
use Prob\Rewrite\Request; |
6
|
|
|
use Prob\Handler\ParameterMap; |
7
|
|
|
use Prob\Handler\Parameter\Typed; |
8
|
|
|
use Prob\Handler\Parameter\Named; |
9
|
|
|
use Prob\Handler\Parameter\TypedAndNamed; |
10
|
|
|
use Prob\Handler\ProcInterface; |
11
|
|
|
use Prob\Router\Map; |
12
|
|
|
use Core\ViewModel; |
13
|
|
|
use Prob\Router\Matcher; |
14
|
|
|
|
15
|
|
|
class ParameterMapper |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Request |
20
|
|
|
*/ |
21
|
|
|
private $request; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ViewModel |
25
|
|
|
*/ |
26
|
|
|
private $viewModel; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Map |
30
|
|
|
*/ |
31
|
|
|
private $routerMap; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ParameterMap |
35
|
|
|
*/ |
36
|
|
|
private $parameterMap; |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function setRequest(Request $request) |
40
|
|
|
{ |
41
|
|
|
$this->request = $request; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function setViewModel(ViewModel $viewModel) |
45
|
|
|
{ |
46
|
|
|
$this->viewModel = $viewModel; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function setRouterMap(Map $routerMap) |
50
|
|
|
{ |
51
|
|
|
$this->routerMap = $routerMap; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return ParameterMap |
56
|
|
|
*/ |
57
|
|
|
public function getParameterMap() |
58
|
|
|
{ |
59
|
|
|
$this->parameterMap = new ParameterMap(); |
60
|
|
|
|
61
|
|
|
$this->bindRequest(); |
62
|
|
|
$this->bindPatternedUrl(); |
63
|
|
|
|
64
|
|
|
$this->bindNamedUrl(); |
65
|
|
|
$this->bindViewModel(); |
66
|
|
|
|
67
|
|
|
$this->bindProc(); |
68
|
|
|
|
69
|
|
|
return $this->parameterMap; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function bindRequest() |
73
|
|
|
{ |
74
|
|
|
$this->parameterMap->bindBy(new Typed(Request::class), $this->request); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
View Code Duplication |
private function bindPatternedUrl() |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
$matcher = new Matcher($this->routerMap); |
80
|
|
|
$urlPattern = $matcher->match($this->request)['urlPattern']; |
81
|
|
|
|
82
|
|
|
$this->parameterMap->bindBy(new Named('urlPattern'), $urlPattern); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function bindNamedUrl() |
86
|
|
|
{ |
87
|
|
|
$urlVariable = $this->resolveUrl(); |
88
|
|
|
$this->parameterMap->bindBy(new TypedAndNamed('array', 'urlVariable'), $urlVariable); |
|
|
|
|
89
|
|
|
|
90
|
|
|
foreach ($urlVariable as $name => $value) { |
91
|
|
|
$this->parameterMap->bindBy(new Named($name), $value); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
View Code Duplication |
private function bindProc() |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$matcher = new Matcher($this->routerMap); |
98
|
|
|
$proc = $matcher->match($this->request)['handler']; |
99
|
|
|
|
100
|
|
|
$this->parameterMap->bindBy(new Typed(ProcInterface::class), $proc); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
private function bindViewModel() |
104
|
|
|
{ |
105
|
|
|
$this->parameterMap->bindBy(new Typed(ViewModel::class), $this->viewModel); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
private function resolveUrl() |
110
|
|
|
{ |
111
|
|
|
$matcher = new Matcher($this->routerMap); |
112
|
|
|
return $matcher->match($this->request)['urlNameMatching'] ?: []; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.