initial commit for soko-web
soko-web/pipeline/head This commit looks good

This commit is contained in:
bence committed 2023-04-07 19:32:15 +02:00
commit a17a88e9d4
71 files changed
+7241

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
<?php namespace SokoWeb\Request;
use SokoWeb\Interfaces\Repository\IUserRepository;
use SokoWeb\Interfaces\Authentication\IUser;
use SokoWeb\Interfaces\Request\IRequest;
use SokoWeb\Interfaces\Request\ISession;
class Request implements IRequest
{
private string $base;
private array $get;
private array $routeParams = [];
private array $post;
private Session $session;
private ?IUser $user = null;
public function __construct(string $base, array &$get, array &$post, array &$session, IUserRepository $userRepository)
{
$this->base = $base;
$this->get = &$get;
$this->post = &$post;
$this->session = new Session($session);
$userId = $this->session->get('userId');
if ($userId !== null) {
$this->user = $userRepository->getById($userId);
}
}
public function setParsedRouteParams(array &$routeParams): void
{
$this->routeParams = &$routeParams;
}
public function getBase(): string
{
return $this->base;
}
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 setUser(?IUser $user): void
{
if ($user === null) {
$this->session->delete('userId');
return;
}
$this->session->set('userId', $user->getUniqueId());
}
public function user(): ?IUser
{
return $this->user;
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php namespace SokoWeb\Request;
use SokoWeb\Interfaces\Request\ISession;
class Session implements ISession
{
private array $data;
public function __construct(array &$data)
{
$this->data = &$data;
}
public function has(string $key): bool
{
return isset($this->data[$key]);
}
public function get(string $key)
{
if (isset($this->data[$key])) {
return $this->data[$key];
}
return null;
}
public function set(string $key, $value): void
{
$this->data[$key] = $value;
}
public function delete(string $key): void
{
unset($this->data[$key]);
}
}