From 3a8e17563329719612cdf81280ebce9ba1581ab4 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 29 Aug 2025 15:54:42 +0800 Subject: [PATCH] fix: request handling with playwright / pest 4 --- src/Utilities/Request.php | 60 ++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/src/Utilities/Request.php b/src/Utilities/Request.php index 97150b87..203ed98c 100644 --- a/src/Utilities/Request.php +++ b/src/Utilities/Request.php @@ -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. * @@ -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); } @@ -42,7 +32,7 @@ public function __call($name, $arguments) */ public function __get($name) { - return $this->request->__get($name); + return request()->__get($name); } /** @@ -50,7 +40,7 @@ public function __get($name) */ public function columns(): array { - return (array) $this->request->input('columns'); + return (array) request()->input('columns'); } /** @@ -58,7 +48,7 @@ public function columns(): array */ public function isSearchable(): bool { - return $this->request->input('search.value') != ''; + return request()->input('search.value') != ''; } /** @@ -66,7 +56,7 @@ public function isSearchable(): bool */ public function isRegex(int $index): bool { - return $this->request->input("columns.$index.search.regex") === 'true'; + return request()->input("columns.$index.search.regex") === 'true'; } /** @@ -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)) { @@ -100,7 +90,7 @@ 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; } /** @@ -108,7 +98,7 @@ public function isOrderable(): bool */ public function isColumnOrderable(int $index): bool { - return $this->request->input("columns.$index.orderable", 'true') == 'true'; + return request()->input("columns.$index.orderable", 'true') == 'true'; } /** @@ -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; @@ -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; } /** @@ -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); } @@ -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); } @@ -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']; } @@ -200,14 +190,14 @@ 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(); } /** @@ -215,7 +205,7 @@ public function getBaseRequest(): BaseRequest */ public function start(): int { - $start = $this->request->input('start', 0); + $start = request()->input('start', 0); return is_numeric($start) ? intval($start) : 0; } @@ -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; } @@ -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; }