MAPG-115 add new classes to store request data (get, post, session, etc.)
This commit is contained in:
		
							parent
							
								
									ecaf8ca9d4
								
							
						
					
					
						commit
						fe814908c7
					
				
							
								
								
									
										10
									
								
								src/Interfaces/Authentication/IUser.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/Interfaces/Authentication/IUser.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
<?php namespace MapGuesser\Interfaces\Authentication;
 | 
			
		||||
 | 
			
		||||
interface IUser
 | 
			
		||||
{
 | 
			
		||||
    const PERMISSION_NORMAL = 0;
 | 
			
		||||
 | 
			
		||||
    const PERMISSION_ADMIN = 1;
 | 
			
		||||
 | 
			
		||||
    public function hasPermission(int $permission): bool;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								src/Interfaces/Request/IRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/Interfaces/Request/IRequest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
<?php namespace MapGuesser\Interfaces\Request;
 | 
			
		||||
 | 
			
		||||
use MapGuesser\Interfaces\Authentication\IUser;
 | 
			
		||||
 | 
			
		||||
interface IRequest
 | 
			
		||||
{
 | 
			
		||||
    public function query(string $key);
 | 
			
		||||
 | 
			
		||||
    public function post(string $key);
 | 
			
		||||
 | 
			
		||||
    public function session(): ISession;
 | 
			
		||||
 | 
			
		||||
    public function user(): ?IUser;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								src/Interfaces/Request/ISession.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/Interfaces/Request/ISession.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
			
		||||
<?php namespace MapGuesser\Interfaces\Request;
 | 
			
		||||
 | 
			
		||||
interface ISession
 | 
			
		||||
{
 | 
			
		||||
    public function has(string $key): bool;
 | 
			
		||||
 | 
			
		||||
    public function get(string $key);
 | 
			
		||||
 | 
			
		||||
    public function set(string $key, $value): void;
 | 
			
		||||
 | 
			
		||||
    public function delete(string $key): void;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										57
									
								
								src/Request/Request.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/Request/Request.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,57 @@
 | 
			
		||||
<?php namespace MapGuesser\Request;
 | 
			
		||||
 | 
			
		||||
use MapGuesser\Interfaces\Authentication\IUser;
 | 
			
		||||
use MapGuesser\Interfaces\Request\IRequest;
 | 
			
		||||
use MapGuesser\Interfaces\Request\ISession;
 | 
			
		||||
use MapGuesser\Model\User;
 | 
			
		||||
 | 
			
		||||
class Request implements IRequest
 | 
			
		||||
{
 | 
			
		||||
    private array $get;
 | 
			
		||||
 | 
			
		||||
    private array $routeParams;
 | 
			
		||||
 | 
			
		||||
    private array $post;
 | 
			
		||||
 | 
			
		||||
    private Session $session;
 | 
			
		||||
 | 
			
		||||
    public function __construct(array &$get, array &$routeParams, array &$post, array &$session)
 | 
			
		||||
    {
 | 
			
		||||
        $this->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');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										37
									
								
								src/Request/Session.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/Request/Session.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
			
		||||
<?php namespace MapGuesser\Request;
 | 
			
		||||
 | 
			
		||||
use MapGuesser\Interfaces\Request\ISession;
 | 
			
		||||
 | 
			
		||||
class Session implements ISession
 | 
			
		||||
{
 | 
			
		||||
    private array $data;
 | 
			
		||||
 | 
			
		||||
    public function __construct(array &$data)
 | 
			
		||||
    {
 | 
			
		||||
        $this->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]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user