From c7e113e325a334fb2a1bb127ea798cee4cc0dab8 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Mon, 7 Oct 2024 11:54:10 +0300 Subject: [PATCH] rest api expand, url params --- kernel/Request.php | 6 +++--- kernel/RestController.php | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/kernel/Request.php b/kernel/Request.php index 970fe57..0a6229c 100644 --- a/kernel/Request.php +++ b/kernel/Request.php @@ -119,11 +119,11 @@ class Request /** * Возвращает GET - параметр. - * @param string $param Параметр. - * @param mixed $defaultValue Значение если, параметр не передан. + * @param string|null $param Параметр. + * @param mixed|null $defaultValue Значение если, параметр не передан. * @return mixed */ - public function get($param = null, $defaultValue = null): mixed + public function get(string $param = null, mixed $defaultValue = null): mixed { if (is_null($param)) { return $_GET; diff --git a/kernel/RestController.php b/kernel/RestController.php index 5bb63b6..0b090e4 100644 --- a/kernel/RestController.php +++ b/kernel/RestController.php @@ -36,9 +36,12 @@ class RestController #[NoReturn] public function actionView($id): void { $expand = $this->expand(); + $request = new Request(); + $expandParams = explode( ",", $request->get('expand') ?? ""); $model = $this->model->where("id", $id)->first(); - if ($expand){ - $model->load($expand); + $finalExpand = array_intersect($expandParams, $expand); + if ($finalExpand){ + $model->load($finalExpand); } $res = []; if ($model){