9
9
*/
10
10
class Request
11
11
{
12
- protected BaseRequest $ request ;
13
-
14
- /**
15
- * Request constructor.
16
- */
17
- public function __construct ()
18
- {
19
- $ this ->request = app ('request ' );
20
- }
21
-
22
12
/**
23
13
* Proxy non-existing method calls to base request class.
24
14
*
@@ -28,7 +18,7 @@ public function __construct()
28
18
*/
29
19
public function __call ($ name , $ arguments )
30
20
{
31
- $ callback = [$ this -> request , $ name ];
21
+ $ callback = [request () , $ name ];
32
22
if (is_callable ($ callback )) {
33
23
return call_user_func_array ($ callback , $ arguments );
34
24
}
@@ -42,31 +32,31 @@ public function __call($name, $arguments)
42
32
*/
43
33
public function __get ($ name )
44
34
{
45
- return $ this -> request ->__get ($ name );
35
+ return request () ->__get ($ name );
46
36
}
47
37
48
38
/**
49
39
* Get all columns request input.
50
40
*/
51
41
public function columns (): array
52
42
{
53
- return (array ) $ this -> request ->input ('columns ' );
43
+ return (array ) request () ->input ('columns ' );
54
44
}
55
45
56
46
/**
57
47
* Check if DataTables is searchable.
58
48
*/
59
49
public function isSearchable (): bool
60
50
{
61
- return $ this -> request ->input ('search.value ' ) != '' ;
51
+ return request () ->input ('search.value ' ) != '' ;
62
52
}
63
53
64
54
/**
65
55
* Check if DataTables must uses regular expressions.
66
56
*/
67
57
public function isRegex (int $ index ): bool
68
58
{
69
- return $ this -> request ->input ("columns. $ index.search.regex " ) === 'true ' ;
59
+ return request () ->input ("columns. $ index.search.regex " ) === 'true ' ;
70
60
}
71
61
72
62
/**
@@ -79,12 +69,12 @@ public function orderableColumns(): array
79
69
}
80
70
81
71
$ orderable = [];
82
- for ($ i = 0 , $ c = count ((array ) $ this -> request ->input ('order ' )); $ i < $ c ; $ i ++) {
72
+ for ($ i = 0 , $ c = count ((array ) request () ->input ('order ' )); $ i < $ c ; $ i ++) {
83
73
/** @var int $order_col */
84
- $ order_col = $ this -> request ->input ("order. $ i.column " );
74
+ $ order_col = request () ->input ("order. $ i.column " );
85
75
86
76
/** @var string $direction */
87
- $ direction = $ this -> request ->input ("order. $ i.dir " );
77
+ $ direction = request () ->input ("order. $ i.dir " );
88
78
89
79
$ order_dir = $ direction && strtolower ($ direction ) === 'asc ' ? 'asc ' : 'desc ' ;
90
80
if ($ this ->isColumnOrderable ($ order_col )) {
@@ -100,15 +90,15 @@ public function orderableColumns(): array
100
90
*/
101
91
public function isOrderable (): bool
102
92
{
103
- return $ this -> request ->input ('order ' ) && count ((array ) $ this -> request ->input ('order ' )) > 0 ;
93
+ return request () ->input ('order ' ) && count ((array ) request () ->input ('order ' )) > 0 ;
104
94
}
105
95
106
96
/**
107
97
* Check if a column is orderable.
108
98
*/
109
99
public function isColumnOrderable (int $ index ): bool
110
100
{
111
- return $ this -> request ->input ("columns. $ index.orderable " , 'true ' ) == 'true ' ;
101
+ return request () ->input ("columns. $ index.orderable " , 'true ' ) == 'true ' ;
112
102
}
113
103
114
104
/**
@@ -119,7 +109,7 @@ public function isColumnOrderable(int $index): bool
119
109
public function searchableColumnIndex ()
120
110
{
121
111
$ searchable = [];
122
- $ columns = (array ) $ this -> request ->input ('columns ' );
112
+ $ columns = (array ) request () ->input ('columns ' );
123
113
for ($ i = 0 , $ c = count ($ columns ); $ i < $ c ; $ i ++) {
124
114
if ($ this ->isColumnSearchable ($ i , false )) {
125
115
$ searchable [] = $ i ;
@@ -137,17 +127,17 @@ public function isColumnSearchable(int $i, bool $column_search = true): bool
137
127
if ($ column_search ) {
138
128
return
139
129
(
140
- $ this -> request ->input ("columns. $ i.searchable " , 'true ' ) === 'true '
130
+ request () ->input ("columns. $ i.searchable " , 'true ' ) === 'true '
141
131
||
142
- $ this -> request ->input ("columns. $ i.searchable " , 'true ' ) === true
132
+ request () ->input ("columns. $ i.searchable " , 'true ' ) === true
143
133
)
144
134
&& $ this ->columnKeyword ($ i ) != '' ;
145
135
}
146
136
147
137
return
148
- $ this -> request ->input ("columns. $ i.searchable " , 'true ' ) === 'true '
138
+ request () ->input ("columns. $ i.searchable " , 'true ' ) === 'true '
149
139
||
150
- $ this -> request ->input ("columns. $ i.searchable " , 'true ' ) === true ;
140
+ request () ->input ("columns. $ i.searchable " , 'true ' ) === true ;
151
141
}
152
142
153
143
/**
@@ -156,7 +146,7 @@ public function isColumnSearchable(int $i, bool $column_search = true): bool
156
146
public function columnKeyword (int $ index ): string
157
147
{
158
148
/** @var string $keyword */
159
- $ keyword = $ this -> request ->input ("columns. $ index.search.value " ) ?? '' ;
149
+ $ keyword = request () ->input ("columns. $ index.search.value " ) ?? '' ;
160
150
161
151
return $ this ->prepareKeyword ($ keyword );
162
152
}
@@ -179,7 +169,7 @@ protected function prepareKeyword(float|array|int|string $keyword): string
179
169
public function keyword (): string
180
170
{
181
171
/** @var string $keyword */
182
- $ keyword = $ this -> request ->input ('search.value ' ) ?? '' ;
172
+ $ keyword = request () ->input ('search.value ' ) ?? '' ;
183
173
184
174
return $ this ->prepareKeyword ($ keyword );
185
175
}
@@ -190,7 +180,7 @@ public function keyword(): string
190
180
public function columnName (int $ i ): ?string
191
181
{
192
182
/** @var string[] $column */
193
- $ column = $ this -> request ->input ("columns. $ i " );
183
+ $ column = request () ->input ("columns. $ i " );
194
184
195
185
return (isset ($ column ['name ' ]) && $ column ['name ' ] != '' ) ? $ column ['name ' ] : $ column ['data ' ];
196
186
}
@@ -200,22 +190,22 @@ public function columnName(int $i): ?string
200
190
*/
201
191
public function isPaginationable (): bool
202
192
{
203
- return ! is_null ($ this -> request ->input ('start ' )) &&
204
- ! is_null ($ this -> request ->input ('length ' )) &&
205
- $ this -> request ->input ('length ' ) != -1 ;
193
+ return ! is_null (request () ->input ('start ' )) &&
194
+ ! is_null (request () ->input ('length ' )) &&
195
+ request () ->input ('length ' ) != -1 ;
206
196
}
207
197
208
198
public function getBaseRequest (): BaseRequest
209
199
{
210
- return $ this -> request ;
200
+ return request () ;
211
201
}
212
202
213
203
/**
214
204
* Get starting record value.
215
205
*/
216
206
public function start (): int
217
207
{
218
- $ start = $ this -> request ->input ('start ' , 0 );
208
+ $ start = request () ->input ('start ' , 0 );
219
209
220
210
return is_numeric ($ start ) ? intval ($ start ) : 0 ;
221
211
}
@@ -225,7 +215,7 @@ public function start(): int
225
215
*/
226
216
public function length (): int
227
217
{
228
- $ length = $ this -> request ->input ('length ' , 10 );
218
+ $ length = request () ->input ('length ' , 10 );
229
219
230
220
return is_numeric ($ length ) ? intval ($ length ) : 10 ;
231
221
}
@@ -235,7 +225,7 @@ public function length(): int
235
225
*/
236
226
public function draw (): int
237
227
{
238
- $ draw = $ this -> request ->input ('draw ' , 0 );
228
+ $ draw = request () ->input ('draw ' , 0 );
239
229
240
230
return is_numeric ($ draw ) ? intval ($ draw ) : 0 ;
241
231
}
0 commit comments