From fda796ab186179cd6bbf7442cf66c7f165d14839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 16 Apr 2023 15:50:53 +0200 Subject: [PATCH] get and serve headers in Request --- src/Interfaces/Request/IRequest.php | 2 ++ src/Request/Request.php | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Interfaces/Request/IRequest.php b/src/Interfaces/Request/IRequest.php index c119057..0df9507 100644 --- a/src/Interfaces/Request/IRequest.php +++ b/src/Interfaces/Request/IRequest.php @@ -12,6 +12,8 @@ interface IRequest public function post(string $key); + public function header(string $key); + public function session(): ISession; public function setUser(?IUser $user): void; diff --git a/src/Request/Request.php b/src/Request/Request.php index 0184fdc..0887e2e 100644 --- a/src/Request/Request.php +++ b/src/Request/Request.php @@ -15,15 +15,24 @@ class Request implements IRequest private array $post; + private array $headers; + private Session $session; private ?IUser $user = null; - public function __construct(string $base, array &$get, array &$post, array &$session, IUserRepository $userRepository) + public function __construct( + string $base, + array &$get, + array &$post, + array $headers, + array &$session, + IUserRepository $userRepository) { $this->base = $base; $this->get = &$get; $this->post = &$post; + $this->headers = $headers; $this->session = new Session($session); $userId = $this->session->get('userId'); @@ -64,6 +73,15 @@ class Request implements IRequest return null; } + public function header($key) + { + if (isset($this->headers[$key])) { + return $this->headers[$key]; + } + + return null; + } + public function session(): ISession { return $this->session; -- 2.45.2