Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 25 additions & 35 deletions src/Utilities/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
*/
class Request
{
protected BaseRequest $request;

/**
* Request constructor.
*/
public function __construct()
{
$this->request = app('request');
}

/**
* Proxy non-existing method calls to base request class.
*
Expand All @@ -28,7 +18,7 @@ public function __construct()
*/
public function __call($name, $arguments)
{
$callback = [$this->request, $name];
$callback = [request(), $name];
if (is_callable($callback)) {
return call_user_func_array($callback, $arguments);
}
Expand All @@ -42,31 +32,31 @@ public function __call($name, $arguments)
*/
public function __get($name)
{
return $this->request->__get($name);
return request()->__get($name);
}

/**
* Get all columns request input.
*/
public function columns(): array
{
return (array) $this->request->input('columns');
return (array) request()->input('columns');
}

/**
* Check if DataTables is searchable.
*/
public function isSearchable(): bool
{
return $this->request->input('search.value') != '';
return request()->input('search.value') != '';
}

/**
* Check if DataTables must uses regular expressions.
*/
public function isRegex(int $index): bool
{
return $this->request->input("columns.$index.search.regex") === 'true';
return request()->input("columns.$index.search.regex") === 'true';
}

/**
Expand All @@ -79,12 +69,12 @@ public function orderableColumns(): array
}

$orderable = [];
for ($i = 0, $c = count((array) $this->request->input('order')); $i < $c; $i++) {
for ($i = 0, $c = count((array) request()->input('order')); $i < $c; $i++) {
/** @var int $order_col */
$order_col = $this->request->input("order.$i.column");
$order_col = request()->input("order.$i.column");

/** @var string $direction */
$direction = $this->request->input("order.$i.dir");
$direction = request()->input("order.$i.dir");

$order_dir = $direction && strtolower($direction) === 'asc' ? 'asc' : 'desc';
if ($this->isColumnOrderable($order_col)) {
Expand All @@ -100,15 +90,15 @@ public function orderableColumns(): array
*/
public function isOrderable(): bool
{
return $this->request->input('order') && count((array) $this->request->input('order')) > 0;
return request()->input('order') && count((array) request()->input('order')) > 0;
}

/**
* Check if a column is orderable.
*/
public function isColumnOrderable(int $index): bool
{
return $this->request->input("columns.$index.orderable", 'true') == 'true';
return request()->input("columns.$index.orderable", 'true') == 'true';
}

/**
Expand All @@ -119,7 +109,7 @@ public function isColumnOrderable(int $index): bool
public function searchableColumnIndex()
{
$searchable = [];
$columns = (array) $this->request->input('columns');
$columns = (array) request()->input('columns');
for ($i = 0, $c = count($columns); $i < $c; $i++) {
if ($this->isColumnSearchable($i, false)) {
$searchable[] = $i;
Expand All @@ -137,17 +127,17 @@ public function isColumnSearchable(int $i, bool $column_search = true): bool
if ($column_search) {
return
(
$this->request->input("columns.$i.searchable", 'true') === 'true'
request()->input("columns.$i.searchable", 'true') === 'true'
||
$this->request->input("columns.$i.searchable", 'true') === true
request()->input("columns.$i.searchable", 'true') === true
)
&& $this->columnKeyword($i) != '';
}

return
$this->request->input("columns.$i.searchable", 'true') === 'true'
request()->input("columns.$i.searchable", 'true') === 'true'
||
$this->request->input("columns.$i.searchable", 'true') === true;
request()->input("columns.$i.searchable", 'true') === true;
}

/**
Expand All @@ -156,7 +146,7 @@ public function isColumnSearchable(int $i, bool $column_search = true): bool
public function columnKeyword(int $index): string
{
/** @var string $keyword */
$keyword = $this->request->input("columns.$index.search.value") ?? '';
$keyword = request()->input("columns.$index.search.value") ?? '';

return $this->prepareKeyword($keyword);
}
Expand All @@ -179,7 +169,7 @@ protected function prepareKeyword(float|array|int|string $keyword): string
public function keyword(): string
{
/** @var string $keyword */
$keyword = $this->request->input('search.value') ?? '';
$keyword = request()->input('search.value') ?? '';

return $this->prepareKeyword($keyword);
}
Expand All @@ -190,7 +180,7 @@ public function keyword(): string
public function columnName(int $i): ?string
{
/** @var string[] $column */
$column = $this->request->input("columns.$i");
$column = request()->input("columns.$i");

return (isset($column['name']) && $column['name'] != '') ? $column['name'] : $column['data'];
}
Expand All @@ -200,22 +190,22 @@ public function columnName(int $i): ?string
*/
public function isPaginationable(): bool
{
return ! is_null($this->request->input('start')) &&
! is_null($this->request->input('length')) &&
$this->request->input('length') != -1;
return ! is_null(request()->input('start')) &&
! is_null(request()->input('length')) &&
request()->input('length') != -1;
}

public function getBaseRequest(): BaseRequest
{
return $this->request;
return request();
}

/**
* Get starting record value.
*/
public function start(): int
{
$start = $this->request->input('start', 0);
$start = request()->input('start', 0);

return is_numeric($start) ? intval($start) : 0;
}
Expand All @@ -225,7 +215,7 @@ public function start(): int
*/
public function length(): int
{
$length = $this->request->input('length', 10);
$length = request()->input('length', 10);

return is_numeric($length) ? intval($length) : 10;
}
Expand All @@ -235,7 +225,7 @@ public function length(): int
*/
public function draw(): int
{
$draw = $this->request->input('draw', 0);
$draw = request()->input('draw', 0);

return is_numeric($draw) ? intval($draw) : 0;
}
Expand Down