Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Pecee/Http/Input/InputFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@ class InputFile implements IInputItem
/**
* @var string
*/
public $index;
public string $index;

/**
* @var string
*/
public $name;
public string $name;

/**
* @var string|null
*/
public $filename;
public ?string $filename = null;

/**
* @var int|null
*/
public $size;
public ?int $size = null;

/**
* @var int|null
* @var string|null
*/
public $type;
public ?string $type = null;

/**
* @var int
*/
public $errors;
public int $errors = 0;

/**
* @var string|null
*/
public $tmpName;
public ?string $tmpName = null;

public function __construct(string $index)
{
Expand Down Expand Up @@ -74,7 +74,7 @@ public static function createFromArray(array $values): self
'error' => null,
];

return (new static($values['index']))
return (new self($values['index']))
->setSize((int)$values['size'])
->setError((int)$values['error'])
->setType($values['type'])
Expand Down Expand Up @@ -104,9 +104,9 @@ public function setIndex(string $index): IInputItem
}

/**
* @return string
* @return int
*/
public function getSize(): string
public function getSize(): ?int
{
return $this->size;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Pecee/Http/Input/InputHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,40 @@ class InputHandler
/**
* @var array
*/
protected $get = [];
protected array $get = [];

/**
* @var array
*/
protected $post = [];
protected array $post = [];

/**
* @var array
*/
protected $file = [];
protected array $file = [];

/**
* @var Request
*/
protected $request;
protected Request $request;

/**
* Original post variables
* @var array
*/
protected $originalPost = [];
protected array $originalPost = [];

/**
* Original get/params variables
* @var array
*/
protected $originalParams = [];
protected array $originalParams = [];

/**
* Get original file variables
* @var array
*/
protected $originalFile = [];
protected array $originalFile = [];

/**
* Input constructor.
Expand Down
12 changes: 10 additions & 2 deletions src/Pecee/Http/Input/InputItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@

class InputItem implements ArrayAccess, IInputItem, IteratorAggregate
{
public $index;
public $name;
public string $index;
public string $name;

/**
* @var mixed|null
*/
public $value;

/**
* @param string $index
* @param mixed $value
*/
public function __construct(string $index, $value = null)
{
$this->index = $index;
Expand Down
6 changes: 3 additions & 3 deletions src/Pecee/Http/Middleware/BaseCsrfVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ class BaseCsrfVerifier implements IMiddleware
* For example: /admin/*
* @var array|null
*/
protected $except;
protected ?array $except = null;

/**
* Urls to include. Can be used to include urls from a certain path.
* @var array|null
*/
protected $include;
protected ?array $include = null;

/**
* @var ITokenProvider
*/
protected $tokenProvider;
protected ITokenProvider $tokenProvider;

/**
* BaseCsrfVerifier constructor.
Expand Down
4 changes: 2 additions & 2 deletions src/Pecee/Http/Middleware/IpRestrictAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

abstract class IpRestrictAccess implements IMiddleware
{
protected $ipBlacklist = [];
protected $ipWhitelist = [];
protected array $ipBlacklist = [];
protected array $ipWhitelist = [];

protected function validate(string $ip): bool
{
Expand Down
36 changes: 19 additions & 17 deletions src/Pecee/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Request
* All request-types
* @var string[]
*/
public static $requestTypes = [
public static array $requestTypes = [
self::REQUEST_TYPE_GET,
self::REQUEST_TYPE_POST,
self::REQUEST_TYPE_PUT,
Expand All @@ -43,7 +43,7 @@ class Request
* Post request-types.
* @var string[]
*/
public static $requestTypesPost = [
public static array $requestTypesPost = [
self::REQUEST_TYPE_POST,
self::REQUEST_TYPE_PUT,
self::REQUEST_TYPE_PATCH,
Expand All @@ -55,65 +55,65 @@ class Request
*
* @var array
*/
private $data = [];
private array $data = [];

/**
* Server headers
* @var array
*/
protected $headers = [];
protected array $headers = [];

/**
* Request ContentType
* @var string
*/
protected $contentType;
protected string $contentType;

/**
* Request host
* @var string
* @var string|null
*/
protected $host;
protected ?string $host;

/**
* Current request url
* @var Url
*/
protected $url;
protected Url $url;

/**
* Request method
* @var string
*/
protected $method;
protected string $method;

/**
* Input handler
* @var InputHandler
*/
protected $inputHandler;
protected InputHandler $inputHandler;

/**
* Defines if request has pending rewrite
* @var bool
*/
protected $hasPendingRewrite = false;
protected bool $hasPendingRewrite = false;

/**
* @var ILoadableRoute|null
*/
protected $rewriteRoute;
protected ?ILoadableRoute $rewriteRoute = null;

/**
* Rewrite url
* @var string|null
*/
protected $rewriteUrl;
protected ?string $rewriteUrl = null;

/**
* @var array
*/
protected $loadedRoutes = [];
protected array $loadedRoutes = [];

/**
* Request constructor.
Expand Down Expand Up @@ -224,15 +224,17 @@ public function getHeaders(): array
*/
public function getIp(bool $safeMode = false): ?string
{
$headers = ['remote-addr'];
$headers = [];
if($safeMode === false) {
$headers = array_merge($headers, [
$headers = [
'http-cf-connecting-ip',
'http-client-ip',
'http-x-forwarded-for',
]);
];
}

$headers[] = 'remote-addr';

return $this->getFirstHeader($headers);
}

Expand Down
6 changes: 1 addition & 5 deletions src/Pecee/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Response
{
protected $request;
protected Request $request;

public function __construct(Request $request)
{
Expand Down Expand Up @@ -39,9 +39,6 @@ public function redirect(string $url, ?int $httpCode = null): void
$this->httpCode($httpCode);
}

// Gracefully end session (avoid any changes being lost)
session_write_close();

$this->header('location: ' . $url);
exit(0);
}
Expand All @@ -68,7 +65,6 @@ public function auth(string $name = ''): self

public function cache(string $eTag, int $lastModifiedTime = 2592000): self
{

$this->headers([
'Cache-Control: public',
sprintf('Last-Modified: %s GMT', gmdate('D, d M Y H:i:s', $lastModifiedTime)),
Expand Down
4 changes: 2 additions & 2 deletions src/Pecee/Http/Security/CookieTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class CookieTokenProvider implements ITokenProvider
/**
* @var string
*/
protected $token;
protected ?string $token = null;

/**
* @var int
*/
protected $cookieTimeoutMinutes = 120;
protected int $cookieTimeoutMinutes = 120;

/**
* CookieTokenProvider constructor.
Expand Down
20 changes: 10 additions & 10 deletions src/Pecee/Http/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,53 @@ class Url implements JsonSerializable
/**
* @var string|null
*/
private $originalUrl;
private ?string $originalUrl = null;

/**
* @var string|null
*/
private $scheme;
private ?string $scheme = null;

/**
* @var string|null
*/
private $host;
private ?string $host = null;

/**
* @var int|null
*/
private $port;
private ?int $port = null;

/**
* @var string|null
*/
private $username;
private ?string $username = null;

/**
* @var string|null
*/
private $password;
private ?string $password = null;

/**
* @var string|null
*/
private $path;
private ?string $path = null;

/**
* Original path with no sanitization to ending slash
* @var string|null
*/
private $originalPath;
private ?string $originalPath = null;

/**
* @var array
*/
private $params = [];
private array $params = [];

/**
* @var string|null
*/
private $fragment;
private ?string $fragment = null;

/**
* Url constructor.
Expand Down
Loading