From fe814908c71901ceb8aae5828550f0c268e6a73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Tue, 9 Jun 2020 00:54:44 +0200 Subject: [PATCH] MAPG-115 add new classes to store request data (get, post, session, etc.) --- src/Interfaces/Authentication/IUser.php | 10 +++++ src/Interfaces/Request/IRequest.php | 14 ++++++ src/Interfaces/Request/ISession.php | 12 ++++++ src/Request/Request.php | 57 +++++++++++++++++++++++++ src/Request/Session.php | 37 ++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 src/Interfaces/Authentication/IUser.php create mode 100644 src/Interfaces/Request/IRequest.php create mode 100644 src/Interfaces/Request/ISession.php create mode 100644 src/Request/Request.php create mode 100644 src/Request/Session.php diff --git a/src/Interfaces/Authentication/IUser.php b/src/Interfaces/Authentication/IUser.php new file mode 100644 index 0000000..363cfe8 --- /dev/null +++ b/src/Interfaces/Authentication/IUser.php @@ -0,0 +1,10 @@ +get = &$get; + $this->routeParams = &$routeParams; + $this->post = &$post; + $this->session = new Session($session); + } + + public function query($key) + { + if (isset($this->get[$key])) { + return $this->get[$key]; + } + + if (isset($this->routeParams[$key])) { + return $this->routeParams[$key]; + } + + return null; + } + + public function post($key) + { + if (isset($this->post[$key])) { + return $this->post[$key]; + } + + return null; + } + + public function session(): ISession + { + return $this->session; + } + + public function user(): ?IUser + { + return $this->session->get('user'); + } +} diff --git a/src/Request/Session.php b/src/Request/Session.php new file mode 100644 index 0000000..f1fedab --- /dev/null +++ b/src/Request/Session.php @@ -0,0 +1,37 @@ +data = &$data; + } + + public function has($key): bool + { + return isset($this->data[$key]); + } + + public function get($key) + { + if (isset($this->data[$key])) { + return $this->data[$key]; + } + + return null; + } + + public function set($key, $value): void + { + $this->data[$key] = $value; + } + + public function delete($key): void + { + unset($this->data[$key]); + } +}