Skip to content

Commit

Permalink
Changed private static array-properties to const
Browse files Browse the repository at this point in the history
  • Loading branch information
simonberger committed Jan 24, 2021
1 parent 7f49c84 commit 8248745
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Cookie
private $secureDefault = false;

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

/**
* Creates cookie from raw header string.
Expand Down Expand Up @@ -149,7 +149,7 @@ public function __toString()
if ($this->isRaw()) {
$str = $this->getName();
} else {
$str = str_replace(self::$reservedCharsFrom, self::$reservedCharsTo, $this->getName());
$str = str_replace(self::RESERVED_CHARS_FROM, self::RESERVED_CHARS_TO, $this->getName());
}

$str .= '=';
Expand Down
8 changes: 4 additions & 4 deletions FileBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class FileBag extends ParameterBag
{
private static $fileKeys = ['error', 'name', 'size', 'tmp_name', 'type'];
private const FILE_KEYS = ['error', 'name', 'size', 'tmp_name', 'type'];

/**
* @param array|UploadedFile[] $parameters An array of HTTP files
Expand Down Expand Up @@ -80,7 +80,7 @@ protected function convertFileInformation($file)
$keys = array_keys($file);
sort($keys);

if ($keys == self::$fileKeys) {
if (self::FILE_KEYS == $keys) {
if (\UPLOAD_ERR_NO_FILE == $file['error']) {
$file = null;
} else {
Expand Down Expand Up @@ -118,12 +118,12 @@ protected function fixPhpFilesArray($data)
$keys = array_keys($data);
sort($keys);

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

$files = $data;
foreach (self::$fileKeys as $k) {
foreach (self::FILE_KEYS as $k) {
unset($files[$k]);
}

Expand Down
16 changes: 8 additions & 8 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class Request

private static $trustedHeaderSet = -1;

private static $forwardedParams = [
private const FORWARDED_PARAMS = [
self::HEADER_X_FORWARDED_FOR => 'for',
self::HEADER_X_FORWARDED_HOST => 'host',
self::HEADER_X_FORWARDED_PROTO => 'proto',
Expand All @@ -225,7 +225,7 @@ class Request
* The other headers are non-standard, but widely used
* by popular reverse proxies (like Apache mod_proxy or Amazon EC2).
*/
private static $trustedHeaders = [
private const TRUSTED_HEADERS = [
self::HEADER_FORWARDED => 'FORWARDED',
self::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
self::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
Expand Down Expand Up @@ -1994,17 +1994,17 @@ private function getTrustedValues(int $type, string $ip = null): array
$clientValues = [];
$forwardedValues = [];

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

if ((self::$trustedHeaderSet & self::HEADER_FORWARDED) && $this->headers->has(self::$trustedHeaders[self::HEADER_FORWARDED])) {
$forwarded = $this->headers->get(self::$trustedHeaders[self::HEADER_FORWARDED]);
if ((self::$trustedHeaderSet & self::HEADER_FORWARDED) && $this->headers->has(self::TRUSTED_HEADERS[self::HEADER_FORWARDED])) {
$forwarded = $this->headers->get(self::TRUSTED_HEADERS[self::HEADER_FORWARDED]);
$parts = HeaderUtils::split($forwarded, ',;=');
$forwardedValues = [];
$param = self::$forwardedParams[$type];
$param = self::FORWARDED_PARAMS[$type];
foreach ($parts as $subParts) {
if (null === $v = HeaderUtils::combine($subParts)[$param] ?? null) {
continue;
Expand Down Expand Up @@ -2037,7 +2037,7 @@ private function getTrustedValues(int $type, string $ip = null): array
}
$this->isForwardedValid = false;

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]));
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]));
}

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

0 comments on commit 8248745

Please sign in to comment.