Compare commits
	
		
			No commits in common. "master" and "redirect-uri" have entirely different histories.
		
	
	
		
			master
			...
			redirect-u
		
	
		
@ -4,8 +4,6 @@ use SokoWeb\Interfaces\Database\IConnection;
 | 
			
		||||
use SokoWeb\Interfaces\Database\IResultSet;
 | 
			
		||||
use SokoWeb\Interfaces\Database\IStatement;
 | 
			
		||||
use mysqli;
 | 
			
		||||
use DateTime;
 | 
			
		||||
use DateTimeZone;
 | 
			
		||||
 | 
			
		||||
class Connection implements IConnection
 | 
			
		||||
{
 | 
			
		||||
@ -111,16 +109,5 @@ class Connection implements IConnection
 | 
			
		||||
        mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
 | 
			
		||||
        $this->connection = new mysqli($this->host, $this->user, $this->password, $this->db, $this->port, $this->socket);
 | 
			
		||||
        $this->connection->set_charset('utf8mb4');
 | 
			
		||||
        $this->connection->query('SET time_zone = \'' . $this->getTimeZone() . '\'');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function getTimeZone(): string {
 | 
			
		||||
        $tz = new DateTimeZone(date_default_timezone_get());
 | 
			
		||||
        $offset = $tz->getOffset(new DateTime('now', new DateTimeZone('UTC')));
 | 
			
		||||
 | 
			
		||||
        $hours = intdiv($offset, 3600);
 | 
			
		||||
        $minutes = abs(($offset % 3600) / 60);
 | 
			
		||||
 | 
			
		||||
        return sprintf("%+03d:%02d", $hours, $minutes);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -7,15 +7,13 @@ class Request implements IRequest
 | 
			
		||||
{
 | 
			
		||||
    private string $url;
 | 
			
		||||
 | 
			
		||||
    private ?string $method = null;
 | 
			
		||||
    private int $method;
 | 
			
		||||
 | 
			
		||||
    private string $query = '';
 | 
			
		||||
 | 
			
		||||
    private ?string $body = null;
 | 
			
		||||
 | 
			
		||||
    private array $headers = [];
 | 
			
		||||
 | 
			
		||||
    public function __construct(string $url = '', ?string $method = null)
 | 
			
		||||
    public function __construct(string $url = '', int $method = self::HTTP_GET)
 | 
			
		||||
    {
 | 
			
		||||
        $this->url = $url;
 | 
			
		||||
        $this->method = $method;
 | 
			
		||||
@ -26,7 +24,7 @@ class Request implements IRequest
 | 
			
		||||
        $this->url = $url;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setMethod(string $method): void
 | 
			
		||||
    public function setMethod(int $method): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->method = $method;
 | 
			
		||||
    }
 | 
			
		||||
@ -40,11 +38,6 @@ class Request implements IRequest
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setBody(string $body): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->body = $body;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setHeaders(array $headers): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->headers = array_merge($this->headers, $headers);
 | 
			
		||||
@ -54,20 +47,13 @@ class Request implements IRequest
 | 
			
		||||
    {
 | 
			
		||||
        $ch = curl_init();
 | 
			
		||||
 | 
			
		||||
        $url = $this->url . '?' . $this->query;
 | 
			
		||||
        if ($this->method === self::HTTP_POST) {
 | 
			
		||||
            $url = $this->url;
 | 
			
		||||
 | 
			
		||||
        if ($this->body !== null) {
 | 
			
		||||
            if ($this->method === null) {
 | 
			
		||||
                $this->method = self::HTTP_POST;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if ($this->method === self::HTTP_POST) {
 | 
			
		||||
                curl_setopt($ch, CURLOPT_POST, 1);
 | 
			
		||||
            } else {
 | 
			
		||||
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->body);
 | 
			
		||||
            curl_setopt($ch, CURLOPT_POST, 1);
 | 
			
		||||
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->query);
 | 
			
		||||
        } else {
 | 
			
		||||
            $url = $this->url . '?' . $this->query;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        curl_setopt($ch, CURLOPT_URL, $url);
 | 
			
		||||
 | 
			
		||||
@ -2,24 +2,16 @@
 | 
			
		||||
 | 
			
		||||
interface IRequest
 | 
			
		||||
{
 | 
			
		||||
    const HTTP_GET = 'GET';
 | 
			
		||||
    const HTTP_GET = 0;
 | 
			
		||||
 | 
			
		||||
    const HTTP_POST = 'POST';
 | 
			
		||||
 | 
			
		||||
    const HTTP_PUT = 'PUT';
 | 
			
		||||
 | 
			
		||||
    const HTTP_PATCH = 'PATCH';
 | 
			
		||||
 | 
			
		||||
    const HTTP_DELETE = 'DELETE';
 | 
			
		||||
    const HTTP_POST = 1;
 | 
			
		||||
 | 
			
		||||
    public function setUrl(string $url): void;
 | 
			
		||||
 | 
			
		||||
    public function setMethod(string $method): void;
 | 
			
		||||
    public function setMethod(int $method): void;
 | 
			
		||||
 | 
			
		||||
    public function setQuery($query): void;
 | 
			
		||||
 | 
			
		||||
    public function setBody(string $body): void;
 | 
			
		||||
 | 
			
		||||
    public function setHeaders(array $headers): void;
 | 
			
		||||
 | 
			
		||||
    public function send(): IResponse;
 | 
			
		||||
 | 
			
		||||
@ -170,7 +170,7 @@ class HttpResponse
 | 
			
		||||
        $this->request->session()->set('redirect_after_login', $this->rawUrl);
 | 
			
		||||
        $response = new Redirect(
 | 
			
		||||
            $this->routeCollection->getRoute($this->appConfig['loginRouteId'])
 | 
			
		||||
                ->generateLink(['redirect_after_login' => $this->rawUrl]),
 | 
			
		||||
                ->generateLink(['redirect_after_login' => urlencode($this->rawUrl)]),
 | 
			
		||||
            IRedirect::TEMPORARY);
 | 
			
		||||
        header('Location: ' . $this->getRedirectUrl($response), true, $response->getHttpCode());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,7 @@ class Route implements IRoute
 | 
			
		||||
        foreach ($this->pattern as $fragment) {
 | 
			
		||||
            if (preg_match('/^{(\\w+)(\\?)?}$/', $fragment, $matches) === 1) {
 | 
			
		||||
                if (isset($parameters[$matches[1]])) {
 | 
			
		||||
                    $link[] = rawurlencode($parameters[$matches[1]]);
 | 
			
		||||
                    $link[] = $parameters[$matches[1]];
 | 
			
		||||
                    unset($parameters[$matches[1]]);
 | 
			
		||||
                } elseif (!isset($matches[2])) {//TODO: why? parameter not found but not optional
 | 
			
		||||
                    $link[] = $fragment;
 | 
			
		||||
@ -53,7 +53,7 @@ class Route implements IRoute
 | 
			
		||||
            $queryParams[$key] = $value;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $query = count($queryParams) > 0 ? '?' . http_build_query($queryParams, encoding_type: PHP_QUERY_RFC3986) : '';
 | 
			
		||||
        $query = count($queryParams) > 0 ? '?' . http_build_query($queryParams) : '';
 | 
			
		||||
 | 
			
		||||
        return '/' . implode('/', $link) . $query;
 | 
			
		||||
    }
 | 
			
		||||
@ -64,7 +64,7 @@ class Route implements IRoute
 | 
			
		||||
 | 
			
		||||
        foreach ($path as $i => $fragment) {
 | 
			
		||||
            if (preg_match('/^{(\\w+)(?:\\?)?}$/', $this->pattern[$i], $matches) === 1) {
 | 
			
		||||
                $parameters[$matches[1]] = rawurldecode($fragment);
 | 
			
		||||
                $parameters[$matches[1]] = $fragment;
 | 
			
		||||
            } elseif ($fragment != $this->pattern[$i]) {
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user