Skip to content

Commit 8248745

Browse files
committed
Changed private static array-properties to const
1 parent 7f49c84 commit 8248745

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

Cookie.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class Cookie
3535
private $secureDefault = false;
3636

3737
private static $reservedCharsList = "=,; \t\r\n\v\f";
38-
private static $reservedCharsFrom = ['=', ',', ';', ' ', "\t", "\r", "\n", "\v", "\f"];
39-
private static $reservedCharsTo = ['%3D', '%2C', '%3B', '%20', '%09', '%0D', '%0A', '%0B', '%0C'];
38+
private const RESERVED_CHARS_FROM = ['=', ',', ';', ' ', "\t", "\r", "\n", "\v", "\f"];
39+
private const RESERVED_CHARS_TO = ['%3D', '%2C', '%3B', '%20', '%09', '%0D', '%0A', '%0B', '%0C'];
4040

4141
/**
4242
* Creates cookie from raw header string.
@@ -149,7 +149,7 @@ public function __toString()
149149
if ($this->isRaw()) {
150150
$str = $this->getName();
151151
} else {
152-
$str = str_replace(self::$reservedCharsFrom, self::$reservedCharsTo, $this->getName());
152+
$str = str_replace(self::RESERVED_CHARS_FROM, self::RESERVED_CHARS_TO, $this->getName());
153153
}
154154

155155
$str .= '=';

FileBag.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class FileBag extends ParameterBag
2323
{
24-
private static $fileKeys = ['error', 'name', 'size', 'tmp_name', 'type'];
24+
private const FILE_KEYS = ['error', 'name', 'size', 'tmp_name', 'type'];
2525

2626
/**
2727
* @param array|UploadedFile[] $parameters An array of HTTP files
@@ -80,7 +80,7 @@ protected function convertFileInformation($file)
8080
$keys = array_keys($file);
8181
sort($keys);
8282

83-
if ($keys == self::$fileKeys) {
83+
if (self::FILE_KEYS == $keys) {
8484
if (\UPLOAD_ERR_NO_FILE == $file['error']) {
8585
$file = null;
8686
} else {
@@ -118,12 +118,12 @@ protected function fixPhpFilesArray($data)
118118
$keys = array_keys($data);
119119
sort($keys);
120120

121-
if (self::$fileKeys != $keys || !isset($data['name']) || !\is_array($data['name'])) {
121+
if (self::FILE_KEYS != $keys || !isset($data['name']) || !\is_array($data['name'])) {
122122
return $data;
123123
}
124124

125125
$files = $data;
126-
foreach (self::$fileKeys as $k) {
126+
foreach (self::FILE_KEYS as $k) {
127127
unset($files[$k]);
128128
}
129129

Request.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Request
209209

210210
private static $trustedHeaderSet = -1;
211211

212-
private static $forwardedParams = [
212+
private const FORWARDED_PARAMS = [
213213
self::HEADER_X_FORWARDED_FOR => 'for',
214214
self::HEADER_X_FORWARDED_HOST => 'host',
215215
self::HEADER_X_FORWARDED_PROTO => 'proto',
@@ -225,7 +225,7 @@ class Request
225225
* The other headers are non-standard, but widely used
226226
* by popular reverse proxies (like Apache mod_proxy or Amazon EC2).
227227
*/
228-
private static $trustedHeaders = [
228+
private const TRUSTED_HEADERS = [
229229
self::HEADER_FORWARDED => 'FORWARDED',
230230
self::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
231231
self::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
@@ -1994,17 +1994,17 @@ private function getTrustedValues(int $type, string $ip = null): array
19941994
$clientValues = [];
19951995
$forwardedValues = [];
19961996

1997-
if ((self::$trustedHeaderSet & $type) && $this->headers->has(self::$trustedHeaders[$type])) {
1998-
foreach (explode(',', $this->headers->get(self::$trustedHeaders[$type])) as $v) {
1997+
if ((self::$trustedHeaderSet & $type) && $this->headers->has(self::TRUSTED_HEADERS[$type])) {
1998+
foreach (explode(',', $this->headers->get(self::TRUSTED_HEADERS[$type])) as $v) {
19991999
$clientValues[] = (self::HEADER_X_FORWARDED_PORT === $type ? '0.0.0.0:' : '').trim($v);
20002000
}
20012001
}
20022002

2003-
if ((self::$trustedHeaderSet & self::HEADER_FORWARDED) && $this->headers->has(self::$trustedHeaders[self::HEADER_FORWARDED])) {
2004-
$forwarded = $this->headers->get(self::$trustedHeaders[self::HEADER_FORWARDED]);
2003+
if ((self::$trustedHeaderSet & self::HEADER_FORWARDED) && $this->headers->has(self::TRUSTED_HEADERS[self::HEADER_FORWARDED])) {
2004+
$forwarded = $this->headers->get(self::TRUSTED_HEADERS[self::HEADER_FORWARDED]);
20052005
$parts = HeaderUtils::split($forwarded, ',;=');
20062006
$forwardedValues = [];
2007-
$param = self::$forwardedParams[$type];
2007+
$param = self::FORWARDED_PARAMS[$type];
20082008
foreach ($parts as $subParts) {
20092009
if (null === $v = HeaderUtils::combine($subParts)[$param] ?? null) {
20102010
continue;
@@ -2037,7 +2037,7 @@ private function getTrustedValues(int $type, string $ip = null): array
20372037
}
20382038
$this->isForwardedValid = false;
20392039

2040-
throw new ConflictingHeadersException(sprintf('The request has both a trusted "%s" header and a trusted "%s" header, conflicting with each other. You should either configure your proxy to remove one of them, or configure your project to distrust the offending one.', self::$trustedHeaders[self::HEADER_FORWARDED], self::$trustedHeaders[$type]));
2040+
throw new ConflictingHeadersException(sprintf('The request has both a trusted "%s" header and a trusted "%s" header, conflicting with each other. You should either configure your proxy to remove one of them, or configure your project to distrust the offending one.', self::TRUSTED_HEADERS[self::HEADER_FORWARDED], self::TRUSTED_HEADERS[$type]));
20412041
}
20422042

20432043
private function normalizeAndFilterClientIps(array $clientIps, string $ip): array

0 commit comments

Comments
 (0)