Skip to content

Commit 8477ea1

Browse files
authored
Merge pull request #645 from skipperbent/v5-development
Version 5.2.0.0
2 parents 4121011 + 77da37e commit 8477ea1

25 files changed

+135
-129
lines changed

src/Pecee/Http/Input/InputFile.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,37 @@ class InputFile implements IInputItem
99
/**
1010
* @var string
1111
*/
12-
public $index;
12+
public string $index;
1313

1414
/**
1515
* @var string
1616
*/
17-
public $name;
17+
public string $name;
1818

1919
/**
2020
* @var string|null
2121
*/
22-
public $filename;
22+
public ?string $filename = null;
2323

2424
/**
2525
* @var int|null
2626
*/
27-
public $size;
27+
public ?int $size = null;
2828

2929
/**
30-
* @var int|null
30+
* @var string|null
3131
*/
32-
public $type;
32+
public ?string $type = null;
3333

3434
/**
3535
* @var int
3636
*/
37-
public $errors;
37+
public int $errors = 0;
3838

3939
/**
4040
* @var string|null
4141
*/
42-
public $tmpName;
42+
public ?string $tmpName = null;
4343

4444
public function __construct(string $index)
4545
{
@@ -74,7 +74,7 @@ public static function createFromArray(array $values): self
7474
'error' => null,
7575
];
7676

77-
return (new static($values['index']))
77+
return (new self($values['index']))
7878
->setSize((int)$values['size'])
7979
->setError((int)$values['error'])
8080
->setType($values['type'])
@@ -104,9 +104,9 @@ public function setIndex(string $index): IInputItem
104104
}
105105

106106
/**
107-
* @return string
107+
* @return int
108108
*/
109-
public function getSize(): string
109+
public function getSize(): ?int
110110
{
111111
return $this->size;
112112
}

src/Pecee/Http/Input/InputHandler.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,40 @@ class InputHandler
1010
/**
1111
* @var array
1212
*/
13-
protected $get = [];
13+
protected array $get = [];
1414

1515
/**
1616
* @var array
1717
*/
18-
protected $post = [];
18+
protected array $post = [];
1919

2020
/**
2121
* @var array
2222
*/
23-
protected $file = [];
23+
protected array $file = [];
2424

2525
/**
2626
* @var Request
2727
*/
28-
protected $request;
28+
protected Request $request;
2929

3030
/**
3131
* Original post variables
3232
* @var array
3333
*/
34-
protected $originalPost = [];
34+
protected array $originalPost = [];
3535

3636
/**
3737
* Original get/params variables
3838
* @var array
3939
*/
40-
protected $originalParams = [];
40+
protected array $originalParams = [];
4141

4242
/**
4343
* Get original file variables
4444
* @var array
4545
*/
46-
protected $originalFile = [];
46+
protected array $originalFile = [];
4747

4848
/**
4949
* Input constructor.

src/Pecee/Http/Input/InputItem.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88

99
class InputItem implements ArrayAccess, IInputItem, IteratorAggregate
1010
{
11-
public $index;
12-
public $name;
11+
public string $index;
12+
public string $name;
13+
14+
/**
15+
* @var mixed|null
16+
*/
1317
public $value;
1418

19+
/**
20+
* @param string $index
21+
* @param mixed $value
22+
*/
1523
public function __construct(string $index, $value = null)
1624
{
1725
$this->index = $index;

src/Pecee/Http/Middleware/BaseCsrfVerifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ class BaseCsrfVerifier implements IMiddleware
1717
* For example: /admin/*
1818
* @var array|null
1919
*/
20-
protected $except;
20+
protected ?array $except = null;
2121

2222
/**
2323
* Urls to include. Can be used to include urls from a certain path.
2424
* @var array|null
2525
*/
26-
protected $include;
26+
protected ?array $include = null;
2727

2828
/**
2929
* @var ITokenProvider
3030
*/
31-
protected $tokenProvider;
31+
protected ITokenProvider $tokenProvider;
3232

3333
/**
3434
* BaseCsrfVerifier constructor.

src/Pecee/Http/Middleware/IpRestrictAccess.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
abstract class IpRestrictAccess implements IMiddleware
99
{
10-
protected $ipBlacklist = [];
11-
protected $ipWhitelist = [];
10+
protected array $ipBlacklist = [];
11+
protected array $ipWhitelist = [];
1212

1313
protected function validate(string $ip): bool
1414
{

src/Pecee/Http/Request.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Request
2929
* All request-types
3030
* @var string[]
3131
*/
32-
public static $requestTypes = [
32+
public static array $requestTypes = [
3333
self::REQUEST_TYPE_GET,
3434
self::REQUEST_TYPE_POST,
3535
self::REQUEST_TYPE_PUT,
@@ -43,7 +43,7 @@ class Request
4343
* Post request-types.
4444
* @var string[]
4545
*/
46-
public static $requestTypesPost = [
46+
public static array $requestTypesPost = [
4747
self::REQUEST_TYPE_POST,
4848
self::REQUEST_TYPE_PUT,
4949
self::REQUEST_TYPE_PATCH,
@@ -55,65 +55,65 @@ class Request
5555
*
5656
* @var array
5757
*/
58-
private $data = [];
58+
private array $data = [];
5959

6060
/**
6161
* Server headers
6262
* @var array
6363
*/
64-
protected $headers = [];
64+
protected array $headers = [];
6565

6666
/**
6767
* Request ContentType
6868
* @var string
6969
*/
70-
protected $contentType;
70+
protected string $contentType;
7171

7272
/**
7373
* Request host
74-
* @var string
74+
* @var string|null
7575
*/
76-
protected $host;
76+
protected ?string $host;
7777

7878
/**
7979
* Current request url
8080
* @var Url
8181
*/
82-
protected $url;
82+
protected Url $url;
8383

8484
/**
8585
* Request method
8686
* @var string
8787
*/
88-
protected $method;
88+
protected string $method;
8989

9090
/**
9191
* Input handler
9292
* @var InputHandler
9393
*/
94-
protected $inputHandler;
94+
protected InputHandler $inputHandler;
9595

9696
/**
9797
* Defines if request has pending rewrite
9898
* @var bool
9999
*/
100-
protected $hasPendingRewrite = false;
100+
protected bool $hasPendingRewrite = false;
101101

102102
/**
103103
* @var ILoadableRoute|null
104104
*/
105-
protected $rewriteRoute;
105+
protected ?ILoadableRoute $rewriteRoute = null;
106106

107107
/**
108108
* Rewrite url
109109
* @var string|null
110110
*/
111-
protected $rewriteUrl;
111+
protected ?string $rewriteUrl = null;
112112

113113
/**
114114
* @var array
115115
*/
116-
protected $loadedRoutes = [];
116+
protected array $loadedRoutes = [];
117117

118118
/**
119119
* Request constructor.
@@ -224,15 +224,17 @@ public function getHeaders(): array
224224
*/
225225
public function getIp(bool $safeMode = false): ?string
226226
{
227-
$headers = ['remote-addr'];
227+
$headers = [];
228228
if($safeMode === false) {
229-
$headers = array_merge($headers, [
229+
$headers = [
230230
'http-cf-connecting-ip',
231231
'http-client-ip',
232232
'http-x-forwarded-for',
233-
]);
233+
];
234234
}
235235

236+
$headers[] = 'remote-addr';
237+
236238
return $this->getFirstHeader($headers);
237239
}
238240

src/Pecee/Http/Response.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class Response
99
{
10-
protected $request;
10+
protected Request $request;
1111

1212
public function __construct(Request $request)
1313
{
@@ -39,9 +39,6 @@ public function redirect(string $url, ?int $httpCode = null): void
3939
$this->httpCode($httpCode);
4040
}
4141

42-
// Gracefully end session (avoid any changes being lost)
43-
session_write_close();
44-
4542
$this->header('location: ' . $url);
4643
exit(0);
4744
}
@@ -68,7 +65,6 @@ public function auth(string $name = ''): self
6865

6966
public function cache(string $eTag, int $lastModifiedTime = 2592000): self
7067
{
71-
7268
$this->headers([
7369
'Cache-Control: public',
7470
sprintf('Last-Modified: %s GMT', gmdate('D, d M Y H:i:s', $lastModifiedTime)),

src/Pecee/Http/Security/CookieTokenProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class CookieTokenProvider implements ITokenProvider
1212
/**
1313
* @var string
1414
*/
15-
protected $token;
15+
protected ?string $token = null;
1616

1717
/**
1818
* @var int
1919
*/
20-
protected $cookieTimeoutMinutes = 120;
20+
protected int $cookieTimeoutMinutes = 120;
2121

2222
/**
2323
* CookieTokenProvider constructor.

src/Pecee/Http/Url.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,53 @@ class Url implements JsonSerializable
1010
/**
1111
* @var string|null
1212
*/
13-
private $originalUrl;
13+
private ?string $originalUrl = null;
1414

1515
/**
1616
* @var string|null
1717
*/
18-
private $scheme;
18+
private ?string $scheme = null;
1919

2020
/**
2121
* @var string|null
2222
*/
23-
private $host;
23+
private ?string $host = null;
2424

2525
/**
2626
* @var int|null
2727
*/
28-
private $port;
28+
private ?int $port = null;
2929

3030
/**
3131
* @var string|null
3232
*/
33-
private $username;
33+
private ?string $username = null;
3434

3535
/**
3636
* @var string|null
3737
*/
38-
private $password;
38+
private ?string $password = null;
3939

4040
/**
4141
* @var string|null
4242
*/
43-
private $path;
43+
private ?string $path = null;
4444

4545
/**
4646
* Original path with no sanitization to ending slash
4747
* @var string|null
4848
*/
49-
private $originalPath;
49+
private ?string $originalPath = null;
5050

5151
/**
5252
* @var array
5353
*/
54-
private $params = [];
54+
private array $params = [];
5555

5656
/**
5757
* @var string|null
5858
*/
59-
private $fragment;
59+
private ?string $fragment = null;
6060

6161
/**
6262
* Url constructor.

0 commit comments

Comments
 (0)