Upgrade to 4.0.0
This commit is contained in:
@@ -103,14 +103,16 @@ class Environment
|
||||
*
|
||||
* @param array|null $info Optional override for `$_SERVER`
|
||||
*/
|
||||
public function __construct(array|null $options = null, array|null $info = null)
|
||||
{
|
||||
public function __construct(
|
||||
array|null $options = null,
|
||||
array|null $info = null
|
||||
) {
|
||||
$this->detect($options, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server's IP address
|
||||
* @see static::ip
|
||||
* @see ::ip
|
||||
*/
|
||||
public function address(): string|null
|
||||
{
|
||||
@@ -150,13 +152,17 @@ class Environment
|
||||
*
|
||||
* @param array|null $info Optional override for `$_SERVER`
|
||||
*/
|
||||
public function detect(array $options = null, array $info = null): array
|
||||
{
|
||||
$info ??= $_SERVER;
|
||||
$options = array_merge([
|
||||
public function detect(
|
||||
array $options = null,
|
||||
array $info = null
|
||||
): array {
|
||||
$defaults = [
|
||||
'cli' => null,
|
||||
'allowed' => null
|
||||
], $options ?? []);
|
||||
];
|
||||
|
||||
$info ??= $_SERVER;
|
||||
$options = array_merge($defaults, $options ?? []);
|
||||
|
||||
$this->info = static::sanitize($info);
|
||||
$this->cli = $this->detectCli($options['cli']);
|
||||
@@ -235,9 +241,9 @@ class Environment
|
||||
|
||||
$uri = new Uri($url, ['slash' => false]);
|
||||
|
||||
// the current environment is allowed,
|
||||
// stop before the exception below is thrown
|
||||
if ($uri->toString() === $this->baseUrl) {
|
||||
// the current environment is allowed,
|
||||
// stop before the exception below is thrown
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -318,7 +324,11 @@ class Environment
|
||||
// @codeCoverageIgnoreStart
|
||||
$term = getenv('TERM');
|
||||
|
||||
if (substr(PHP_SAPI, 0, 3) === 'cgi' && $term && $term !== 'unknown') {
|
||||
if (
|
||||
substr(PHP_SAPI, 0, 3) === 'cgi' &&
|
||||
$term &&
|
||||
$term !== 'unknown'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -340,8 +350,7 @@ class Environment
|
||||
];
|
||||
|
||||
// prefer the standardized `Forwarded` header if defined
|
||||
$forwarded = $this->get('HTTP_FORWARDED');
|
||||
if ($forwarded) {
|
||||
if ($forwarded = $this->get('HTTP_FORWARDED')) {
|
||||
// only use the first (outermost) proxy by using the first set of values
|
||||
// before the first comma (but only a comma outside of quotes)
|
||||
if (Str::contains($forwarded, ',') === true) {
|
||||
@@ -513,7 +522,9 @@ class Environment
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array(strtolower($protocol), ['https', 'https, http']) === true;
|
||||
$protocols = ['https', 'https, http'];
|
||||
|
||||
return in_array(strtolower($protocol), $protocols) === true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -660,11 +671,12 @@ class Environment
|
||||
* @param mixed $default Optional default value, which should be
|
||||
* returned if no element has been found
|
||||
*/
|
||||
public static function getGlobally(string|false|null $key = null, $default = null)
|
||||
{
|
||||
public static function getGlobally(
|
||||
string|false|null $key = null,
|
||||
$default = null
|
||||
) {
|
||||
// first try the global `Environment` object if the CMS is running
|
||||
$app = App::instance(null, true);
|
||||
if ($app) {
|
||||
if ($app = App::instance(null, true)) {
|
||||
return $app->environment()->get($key, $default);
|
||||
}
|
||||
|
||||
@@ -851,8 +863,10 @@ class Environment
|
||||
/**
|
||||
* Sanitizes some `$_SERVER` keys
|
||||
*/
|
||||
public static function sanitize(string|array $key, $value = null)
|
||||
{
|
||||
public static function sanitize(
|
||||
string|array $key,
|
||||
$value = null
|
||||
) {
|
||||
if (is_array($key) === true) {
|
||||
foreach ($key as $k => $v) {
|
||||
$key[$k] = static::sanitize($k, $v);
|
||||
@@ -877,8 +891,9 @@ class Environment
|
||||
/**
|
||||
* Sanitizes the given host name
|
||||
*/
|
||||
protected static function sanitizeHost(string|null $host = null): string|null
|
||||
{
|
||||
protected static function sanitizeHost(
|
||||
string|null $host = null
|
||||
): string|null {
|
||||
if (empty($host) === true) {
|
||||
return null;
|
||||
}
|
||||
@@ -902,8 +917,9 @@ class Environment
|
||||
/**
|
||||
* Sanitizes the given port number
|
||||
*/
|
||||
protected static function sanitizePort(string|int|false|null $port = null): int|null
|
||||
{
|
||||
protected static function sanitizePort(
|
||||
string|int|false|null $port = null
|
||||
): int|null {
|
||||
// already fine
|
||||
if (is_int($port) === true) {
|
||||
return $port;
|
||||
|
||||
Reference in New Issue
Block a user