1
|
|
|
<?php namespace Arcanedev\Localization\Routing; |
2
|
|
|
|
3
|
|
|
use Closure; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Router |
7
|
|
|
* |
8
|
|
|
* @package Arcanedev\Localization\Routing |
9
|
|
|
* @author ARCANEDEV <[email protected]> |
10
|
|
|
* |
11
|
|
|
* @mixin \Illuminate\Routing\Router |
12
|
|
|
*/ |
13
|
|
|
class Router |
14
|
|
|
{ |
15
|
|
|
/* ----------------------------------------------------------------- |
16
|
|
|
| Getters & Setters |
17
|
|
|
| ----------------------------------------------------------------- |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Get active middlewares. |
22
|
|
|
* |
23
|
|
|
* @return Closure|array |
24
|
|
|
*/ |
25
|
|
|
protected function getActiveMiddlewares() |
26
|
|
|
{ |
27
|
252 |
|
return function() { |
28
|
252 |
|
return array_keys(array_filter( |
29
|
252 |
|
config('localization.route.middleware', []) |
30
|
|
|
)); |
31
|
252 |
|
}; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/* ----------------------------------------------------------------- |
35
|
|
|
| Route Methods |
36
|
|
|
| ----------------------------------------------------------------- |
37
|
|
|
*/ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Create a route group with shared attributes. |
41
|
|
|
* |
42
|
|
|
* @return Closure |
43
|
|
|
*/ |
44
|
|
|
public function localizedGroup() |
45
|
|
|
{ |
46
|
252 |
|
return function(Closure $callback, array $attributes = []) { |
47
|
252 |
|
$attributes = array_merge($attributes, [ |
48
|
252 |
|
'prefix' => localization()->setLocale(), |
49
|
252 |
|
'middleware' => $this->getActiveMiddlewares(), |
50
|
|
|
]); |
51
|
|
|
|
52
|
252 |
|
$this->group(array_filter($attributes), $callback); |
|
|
|
|
53
|
252 |
|
}; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Register a new translated GET route with the router. |
58
|
|
|
* |
59
|
|
|
* @return Closure|\Illuminate\Routing\Route |
60
|
|
|
*/ |
61
|
|
|
public function transGet() |
62
|
|
|
{ |
63
|
252 |
|
return function($trans, $action) { |
64
|
252 |
|
return $this->get( |
|
|
|
|
65
|
252 |
|
localization()->transRoute($trans), $action |
66
|
|
|
); |
67
|
252 |
|
}; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Register a new translated POST route with the router. |
72
|
|
|
* |
73
|
|
|
* @return Closure|\Illuminate\Routing\Route |
74
|
|
|
*/ |
75
|
|
|
public function transPost() |
76
|
|
|
{ |
77
|
252 |
|
return function($trans, $action) { |
78
|
252 |
|
return $this->post( |
|
|
|
|
79
|
252 |
|
localization()->transRoute($trans), $action |
80
|
|
|
); |
81
|
252 |
|
}; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Register a new translated PUT route with the router. |
86
|
|
|
* |
87
|
|
|
* @return Closure|\Illuminate\Routing\Route |
88
|
|
|
*/ |
89
|
|
|
public function transPut() |
90
|
|
|
{ |
91
|
252 |
|
return function($trans, $action) { |
92
|
252 |
|
return $this->put( |
|
|
|
|
93
|
252 |
|
localization()->transRoute($trans), $action |
94
|
|
|
); |
95
|
252 |
|
}; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Register a new translated PATCH route with the router. |
100
|
|
|
* |
101
|
|
|
* @return Closure|\Illuminate\Routing\Route |
102
|
|
|
*/ |
103
|
|
|
public function transPatch() |
104
|
|
|
{ |
105
|
252 |
|
return function($trans, $action) { |
106
|
252 |
|
return $this->patch( |
|
|
|
|
107
|
252 |
|
localization()->transRoute($trans), $action |
108
|
|
|
); |
109
|
252 |
|
}; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Register a new translated DELETE route with the router. |
114
|
|
|
* |
115
|
|
|
* @return Closure|\Illuminate\Routing\Route |
116
|
|
|
*/ |
117
|
|
|
public function transDelete() |
118
|
|
|
{ |
119
|
252 |
|
return function($trans, $action) { |
120
|
252 |
|
return $this->delete( |
|
|
|
|
121
|
252 |
|
localization()->transRoute($trans), $action |
122
|
|
|
); |
123
|
252 |
|
}; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Register a new translated OPTIONS route with the router. |
128
|
|
|
* |
129
|
|
|
* @return Closure|\Illuminate\Routing\Route |
130
|
|
|
* @internal param string $trans |
131
|
|
|
* @internal param array|Closure|string $action |
132
|
|
|
* |
133
|
|
|
*/ |
134
|
|
|
public function transOptions() |
135
|
|
|
{ |
136
|
252 |
|
return function($trans, $action) { |
137
|
252 |
|
return $this->options( |
|
|
|
|
138
|
252 |
|
localization()->transRoute($trans), $action |
139
|
|
|
); |
140
|
252 |
|
}; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Register a new translated any route with the router. |
145
|
|
|
* |
146
|
|
|
* @return Closure|\Illuminate\Routing\Route |
147
|
|
|
* @internal param string $trans |
148
|
|
|
* @internal param array|Closure|string $action |
149
|
|
|
* |
150
|
|
|
*/ |
151
|
|
|
public function transAny() |
152
|
|
|
{ |
153
|
252 |
|
return function($trans, $action) { |
154
|
252 |
|
return $this->any( |
|
|
|
|
155
|
252 |
|
localization()->transRoute($trans), $action |
156
|
|
|
); |
157
|
252 |
|
}; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
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.