From f44f36380655286ce3f892e54170c025e1404c4c Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 25 May 2021 10:49:34 +0930 Subject: [PATCH] Add Context::fieldRequested --- src/Context.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Context.php b/src/Context.php index 75379bb..f8bf315 100644 --- a/src/Context.php +++ b/src/Context.php @@ -32,8 +32,19 @@ class Context return $this->request; } - public function response(callable $callback) + public function response(callable $callback): void { $this->listeners['response'][] = $callback; } + + public function fieldRequested(string $type, string $field, bool $default = true): bool + { + $queryParams = $this->request->getQueryParams(); + + if (! isset($queryParams['fields'][$type])) { + return $default; + } + + return in_array($field, explode(',', $queryParams['fields'][$type])); + } }