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
|
|
|
| Route Methods |
17
|
|
|
| ----------------------------------------------------------------- |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Create a route group with shared attributes. |
22
|
|
|
* |
23
|
|
|
* @return \Closure |
24
|
|
|
*/ |
25
|
|
|
public function localizedGroup() |
26
|
|
|
{ |
27
|
252 |
|
return function(Closure $callback, array $attributes = []) { |
28
|
252 |
|
$activeMiddleware = array_keys(array_filter( |
29
|
252 |
|
config('localization.route.middleware', []) |
30
|
|
|
)); |
31
|
|
|
|
32
|
252 |
|
$attributes = array_merge($attributes, [ |
33
|
252 |
|
'prefix' => localization()->setLocale(), |
34
|
252 |
|
'middleware' => $activeMiddleware, |
35
|
|
|
]); |
36
|
|
|
|
37
|
252 |
|
$this->group(array_filter($attributes), $callback); |
|
|
|
|
38
|
252 |
|
}; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Register a new translated GET route with the router. |
43
|
|
|
* |
44
|
|
|
* @return \Closure|\Illuminate\Routing\Route |
45
|
|
|
*/ |
46
|
|
|
public function transGet() |
47
|
|
|
{ |
48
|
252 |
|
return function($trans, $action) { |
49
|
252 |
|
return $this->get( |
|
|
|
|
50
|
252 |
|
localization()->transRoute($trans), $action |
51
|
|
|
); |
52
|
252 |
|
}; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Register a new translated POST route with the router. |
57
|
|
|
* |
58
|
|
|
* @return \Closure|\Illuminate\Routing\Route |
59
|
|
|
*/ |
60
|
|
|
public function transPost() |
61
|
|
|
{ |
62
|
252 |
|
return function($trans, $action) { |
63
|
252 |
|
return $this->post( |
|
|
|
|
64
|
252 |
|
localization()->transRoute($trans), $action |
65
|
|
|
); |
66
|
252 |
|
}; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Register a new translated PUT route with the router. |
71
|
|
|
* |
72
|
|
|
* @return \Closure|\Illuminate\Routing\Route |
73
|
|
|
*/ |
74
|
|
|
public function transPut() |
75
|
|
|
{ |
76
|
252 |
|
return function($trans, $action) { |
77
|
252 |
|
return $this->put( |
|
|
|
|
78
|
252 |
|
localization()->transRoute($trans), $action |
79
|
|
|
); |
80
|
252 |
|
}; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Register a new translated PATCH route with the router. |
85
|
|
|
* |
86
|
|
|
* @return \Closure|\Illuminate\Routing\Route |
87
|
|
|
*/ |
88
|
|
|
public function transPatch() |
89
|
|
|
{ |
90
|
252 |
|
return function($trans, $action) { |
91
|
252 |
|
return $this->patch( |
|
|
|
|
92
|
252 |
|
localization()->transRoute($trans), $action |
93
|
|
|
); |
94
|
252 |
|
}; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Register a new translated DELETE route with the router. |
99
|
|
|
* |
100
|
|
|
* @return \Closure|\Illuminate\Routing\Route |
101
|
|
|
*/ |
102
|
|
|
public function transDelete() |
103
|
|
|
{ |
104
|
252 |
|
return function($trans, $action) { |
105
|
252 |
|
return $this->delete( |
|
|
|
|
106
|
252 |
|
localization()->transRoute($trans), $action |
107
|
|
|
); |
108
|
252 |
|
}; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Register a new translated OPTIONS route with the router. |
113
|
|
|
* |
114
|
|
|
* @return \Closure|\Illuminate\Routing\Route |
115
|
|
|
*/ |
116
|
|
|
public function transOptions() |
117
|
|
|
{ |
118
|
252 |
|
return function($trans, $action) { |
119
|
252 |
|
return $this->options( |
|
|
|
|
120
|
252 |
|
localization()->transRoute($trans), $action |
121
|
|
|
); |
122
|
252 |
|
}; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Register a new translated any route with the router. |
127
|
|
|
* |
128
|
|
|
* @return \Closure|\Illuminate\Routing\Route |
129
|
|
|
*/ |
130
|
|
|
public function transAny() |
131
|
|
|
{ |
132
|
252 |
|
return function($trans, $action) { |
133
|
252 |
|
return $this->any( |
|
|
|
|
134
|
252 |
|
localization()->transRoute($trans), $action |
135
|
|
|
); |
136
|
252 |
|
}; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
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.