1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Imanghafoori\HeyMan\Hooks; |
4
|
|
|
|
5
|
|
|
use Imanghafoori\HeyMan\Normilizers\RouteNormalizer; |
6
|
|
|
use Imanghafoori\HeyMan\WatchingStrategies\RouterEventManager; |
7
|
|
|
use Imanghafoori\HeyMan\YouShouldHave; |
8
|
|
|
|
9
|
|
|
trait RouteHooks |
10
|
|
|
{ |
11
|
|
|
use RouteNormalizer; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @param mixed ...$url |
15
|
|
|
* |
16
|
|
|
* @return YouShouldHave |
17
|
|
|
*/ |
18
|
35 |
|
public function whenYouVisitUrl(...$url): YouShouldHave |
19
|
|
|
{ |
20
|
35 |
|
return $this->watchURL($url, 'GET'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param mixed ...$url |
25
|
|
|
* |
26
|
|
|
* @return YouShouldHave |
27
|
|
|
*/ |
28
|
1 |
|
public function whenYouSendPost(...$url): YouShouldHave |
29
|
|
|
{ |
30
|
1 |
|
return $this->watchURL($url, 'POST'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param mixed ...$url |
35
|
|
|
* |
36
|
|
|
* @return YouShouldHave |
37
|
|
|
*/ |
38
|
1 |
|
public function whenYouSendPatch(...$url): YouShouldHave |
39
|
|
|
{ |
40
|
1 |
|
return $this->watchURL($url, 'PATCH'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param mixed ...$url |
45
|
|
|
* |
46
|
|
|
* @return YouShouldHave |
47
|
|
|
*/ |
48
|
2 |
|
public function whenYouSendPut(...$url): YouShouldHave |
49
|
|
|
{ |
50
|
2 |
|
return $this->watchURL($url, 'PUT'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param mixed ...$url |
55
|
|
|
* |
56
|
|
|
* @return YouShouldHave |
57
|
|
|
*/ |
58
|
1 |
|
public function whenYouSendDelete(...$url): YouShouldHave |
59
|
|
|
{ |
60
|
1 |
|
return $this->watchURL($url, 'DELETE'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param mixed ...$routeName |
65
|
|
|
* |
66
|
|
|
* @return YouShouldHave |
67
|
|
|
*/ |
68
|
11 |
|
public function whenYouHitRouteName(...$routeName): YouShouldHave |
69
|
|
|
{ |
70
|
11 |
|
return $this->watchRoute($this->normalizeInput($routeName)); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @deprecated |
75
|
|
|
* |
76
|
|
|
* @param mixed ...$routeName |
77
|
|
|
* |
78
|
|
|
* @return YouShouldHave |
79
|
|
|
*/ |
80
|
11 |
|
public function whenYouReachRoute(...$routeName): YouShouldHave |
81
|
|
|
{ |
82
|
11 |
|
return $this->whenYouHitRouteName(...$routeName); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param mixed ...$action |
87
|
|
|
* |
88
|
|
|
* @return YouShouldHave |
89
|
|
|
*/ |
90
|
10 |
|
public function whenYouCallAction(...$action): YouShouldHave |
91
|
|
|
{ |
92
|
10 |
|
return $this->watchRoute($this->normalizeAction($action)); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param $value |
97
|
|
|
* |
98
|
|
|
* @return YouShouldHave |
99
|
|
|
*/ |
100
|
58 |
|
private function watchRoute($value): YouShouldHave |
101
|
|
|
{ |
102
|
58 |
|
$this->chain->eventManager = app(RouterEventManager::class)->init($value); |
103
|
|
|
|
104
|
58 |
|
return app(YouShouldHave::class); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param $url |
109
|
|
|
* @param $verb |
110
|
|
|
* |
111
|
|
|
* @return YouShouldHave |
112
|
|
|
*/ |
113
|
40 |
|
private function watchURL($url, $verb): YouShouldHave |
114
|
|
|
{ |
115
|
40 |
|
return $this->watchRoute($this->normalizeUrl($url, $verb)); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.