Update to Kirby 4.7.0
This commit is contained in:
parent
02a9ab387c
commit
ba25a9a198
509 changed files with 26604 additions and 14872 deletions
|
@ -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|null $options = null,
|
||||
array|null $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']);
|
||||
|
@ -172,11 +178,11 @@ class Environment
|
|||
if ($options['allowed'] === '*' || $options['allowed'] === ['*']) {
|
||||
$this->detectAuto(true);
|
||||
|
||||
// fixed environments
|
||||
// fixed environments
|
||||
} elseif (empty($options['allowed']) === false) {
|
||||
$this->detectAllowed($options['allowed']);
|
||||
|
||||
// secure auto-detection
|
||||
// secure auto-detection
|
||||
} else {
|
||||
$this->detectAuto();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -316,9 +322,18 @@ class Environment
|
|||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
$sapi = php_sapi_name();
|
||||
if ($sapi === 'cli') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$term = getenv('TERM');
|
||||
|
||||
if (substr(PHP_SAPI, 0, 3) === 'cgi' && $term && $term !== 'unknown') {
|
||||
if (
|
||||
substr($sapi, 0, 3) === 'cgi' &&
|
||||
$term &&
|
||||
$term !== 'unknown'
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -340,8 +355,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 +527,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -586,13 +602,7 @@ class Environment
|
|||
*/
|
||||
protected function detectRequestUri(string|null $requestUri = null): Uri
|
||||
{
|
||||
// make sure the URL parser works properly when there's a
|
||||
// colon in the request URI but the URI is relative
|
||||
if (Url::isAbsolute($requestUri) === false) {
|
||||
$requestUri = 'https://getkirby.com' . $requestUri;
|
||||
}
|
||||
|
||||
$uri = new Uri($requestUri);
|
||||
$uri = new Uri($requestUri ?? '');
|
||||
|
||||
// create the URI object as a combination of base uri parts
|
||||
// and the parts from REQUEST_URI
|
||||
|
@ -660,11 +670,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);
|
||||
}
|
||||
|
||||
|
@ -741,6 +752,10 @@ class Environment
|
|||
return true;
|
||||
}
|
||||
|
||||
if (Str::endsWith($host, '.ddev.site') === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// collect all possible visitor ips
|
||||
$ips = [
|
||||
$this->get('REMOTE_ADDR'),
|
||||
|
@ -851,8 +866,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 +894,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 +920,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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue