1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Imanghafoori\HeyMan\Situations; |
4
|
|
|
|
5
|
|
|
use Imanghafoori\HeyMan\Chain; |
6
|
|
|
use Imanghafoori\HeyMan\Normilizers\InputNormalizer; |
7
|
|
|
use Imanghafoori\HeyMan\Normilizers\RouteNormalizer; |
8
|
|
|
use Imanghafoori\HeyMan\WatchingStrategies\RouterEventManager; |
9
|
|
|
use Imanghafoori\HeyMan\YouShouldHave; |
10
|
|
|
|
11
|
|
|
class RouteSituations |
12
|
|
|
{ |
13
|
|
|
private $chain; |
14
|
|
|
|
15
|
|
|
use InputNormalizer; |
16
|
|
|
use RouteNormalizer; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* HeyMan constructor. |
20
|
|
|
* |
21
|
|
|
* @param Chain $chain |
22
|
|
|
*/ |
23
|
58 |
|
public function __construct(Chain $chain) |
24
|
|
|
{ |
25
|
58 |
|
$this->chain = $chain; |
26
|
58 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param mixed ...$url |
30
|
|
|
* |
31
|
|
|
* @return YouShouldHave |
32
|
|
|
*/ |
33
|
35 |
|
public function whenYouVisitUrl(...$url): YouShouldHave |
34
|
|
|
{ |
35
|
35 |
|
return $this->watchURL($url, 'GET'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param mixed ...$url |
40
|
|
|
* |
41
|
|
|
* @return YouShouldHave |
42
|
|
|
*/ |
43
|
1 |
|
public function whenYouSendPost(...$url): YouShouldHave |
44
|
|
|
{ |
45
|
1 |
|
return $this->watchURL($url, 'POST'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param mixed ...$url |
50
|
|
|
* |
51
|
|
|
* @return YouShouldHave |
52
|
|
|
*/ |
53
|
1 |
|
public function whenYouSendPatch(...$url): YouShouldHave |
54
|
|
|
{ |
55
|
1 |
|
return $this->watchURL($url, 'PATCH'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param mixed ...$url |
60
|
|
|
* |
61
|
|
|
* @return YouShouldHave |
62
|
|
|
*/ |
63
|
2 |
|
public function whenYouSendPut(...$url): YouShouldHave |
64
|
|
|
{ |
65
|
2 |
|
return $this->watchURL($url, 'PUT'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param mixed ...$url |
70
|
|
|
* |
71
|
|
|
* @return YouShouldHave |
72
|
|
|
*/ |
73
|
1 |
|
public function whenYouSendDelete(...$url): YouShouldHave |
74
|
|
|
{ |
75
|
1 |
|
return $this->watchURL($url, 'DELETE'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param mixed ...$routeName |
80
|
|
|
* |
81
|
|
|
* @return YouShouldHave |
82
|
|
|
*/ |
83
|
11 |
|
public function whenYouHitRouteName(...$routeName): YouShouldHave |
84
|
|
|
{ |
85
|
11 |
|
return $this->watchRoute($this->normalizeInput($routeName)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @deprecated |
90
|
|
|
* |
91
|
|
|
* @param mixed ...$routeName |
92
|
|
|
* |
93
|
|
|
* @return YouShouldHave |
94
|
|
|
*/ |
95
|
|
|
public function whenYouReachRoute(...$routeName): YouShouldHave |
96
|
|
|
{ |
97
|
|
|
return $this->whenYouHitRouteName(...$routeName); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param mixed ...$action |
102
|
|
|
* |
103
|
|
|
* @return YouShouldHave |
104
|
|
|
*/ |
105
|
10 |
|
public function whenYouCallAction(...$action): YouShouldHave |
106
|
|
|
{ |
107
|
10 |
|
return $this->watchRoute($this->normalizeAction($action)); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param $value |
112
|
|
|
* |
113
|
|
|
* @return YouShouldHave |
114
|
|
|
*/ |
115
|
58 |
|
private function watchRoute($value): YouShouldHave |
116
|
|
|
{ |
117
|
58 |
|
$this->chain->eventManager = app(RouterEventManager::class)->init($value); |
|
|
|
|
118
|
|
|
|
119
|
58 |
|
return app(YouShouldHave::class); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param $url |
124
|
|
|
* @param $verb |
125
|
|
|
* |
126
|
|
|
* @return YouShouldHave |
127
|
|
|
*/ |
128
|
40 |
|
private function watchURL($url, $verb): YouShouldHave |
129
|
|
|
{ |
130
|
40 |
|
return $this->watchRoute($this->normalizeUrl($url, $verb)); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..