Update Composer packages

This commit is contained in:
Paul Nicoué 2023-04-14 16:30:28 +02:00
parent d482354bdf
commit e7e7361480
219 changed files with 6487 additions and 4444 deletions

View file

@ -217,9 +217,6 @@ class Cookie
{
// lazily request the instance for non-CMS use cases
$kirby = App::instance(null, true);
if ($kirby) {
$kirby->response()->usesCookie($key);
}
$kirby?->response()->usesCookie($key);
}
}

View file

@ -152,7 +152,7 @@ class Environment
*/
public function detect(array $options = null, array $info = null): array
{
$info ??= $_SERVER;
$info ??= $_SERVER;
$options = array_merge([
'cli' => null,
'allowed' => null
@ -195,7 +195,7 @@ class Environment
* Sets the host name, port, path and protocol from the
* fixed list of allowed URLs
*/
protected function detectAllowed(array|string|object $allowed): void
protected function detectAllowed(array|string $allowed): void
{
$allowed = A::wrap($allowed);
@ -922,7 +922,7 @@ class Environment
protected function sanitizeScriptPath(string|null $scriptPath = null): string
{
$scriptPath ??= '';
$scriptPath = trim($scriptPath);
$scriptPath = trim($scriptPath);
// skip all the sanitizing steps if the path is empty
if ($scriptPath === '') {

View file

@ -101,8 +101,11 @@ class Header
*
* @return string|void
*/
public static function type(string $mime, string $charset = 'UTF-8', bool $send = true)
{
public static function type(
string $mime,
string $charset = 'UTF-8',
bool $send = true
) {
return static::contentType($mime, $charset, $send);
}
@ -118,17 +121,25 @@ class Header
* @return string|void
* @psalm-return ($send is false ? string : void)
*/
public static function status(int|string|null $code = null, bool $send = true)
{
public static function status(
int|string|null $code = null,
bool $send = true
) {
$codes = static::$codes;
$protocol = Environment::getGlobally('SERVER_PROTOCOL', 'HTTP/1.1');
// allow full control over code and message
if (is_string($code) === true && preg_match('/^\d{3} \w.+$/', $code) === 1) {
if (
is_string($code) === true &&
preg_match('/^\d{3} \w.+$/', $code) === 1
) {
$message = substr(rtrim($code), 4);
$code = substr($code, 0, 3);
} else {
$code = array_key_exists('_' . $code, $codes) === false ? 500 : $code;
if (array_key_exists('_' . $code, $codes) === false) {
$code = 500;
}
$message = $codes['_' . $code] ?? 'Something went wrong';
}

View file

@ -66,7 +66,7 @@ class Params extends Obj
$paramValue = $paramParts[1] ?? null;
if ($paramKey !== null) {
$params[rawurldecode($paramKey)] = $paramValue ? rawurldecode($paramValue) : null;
$params[rawurldecode($paramKey)] = $paramValue !== null ? rawurldecode($paramValue) : null;
}
unset($path[$index]);
@ -120,8 +120,10 @@ class Params extends Obj
* Converts the params object to a params string
* which can then be used in the URL builder again
*/
public function toString(bool $leadingSlash = false, bool $trailingSlash = false): string
{
public function toString(
bool $leadingSlash = false,
bool $trailingSlash = false
): string {
if ($this->isEmpty() === true) {
return '';
}

View file

@ -31,8 +31,10 @@ class Path extends Collection
return $this->toString();
}
public function toString(bool $leadingSlash = false, bool $trailingSlash = false): string
{
public function toString(
bool $leadingSlash = false,
bool $trailingSlash = false
): string {
if (empty($this->data) === true) {
return '';
}

View file

@ -91,7 +91,13 @@ class Remote
public static function __callStatic(string $method, array $arguments = []): static
{
return new static($arguments[0], array_merge(['method' => strtoupper($method)], $arguments[1] ?? []));
return new static(
url: $arguments[0],
options: array_merge(
['method' => strtoupper($method)],
$arguments[1] ?? []
)
);
}
/**
@ -176,10 +182,10 @@ class Remote
$headers = [];
foreach ($this->options['headers'] as $key => $value) {
if (is_string($key) === true) {
$headers[] = $key . ': ' . $value;
} else {
$headers[] = $value;
$value = $key . ': ' . $value;
}
$headers[] = $value;
}
$this->curlopt[CURLOPT_HTTPHEADER] = $headers;
@ -264,7 +270,10 @@ class Remote
$query = http_build_query($options['data']);
if (empty($query) === false) {
$url = Url::hasQuery($url) === true ? $url . '&' . $query : $url . '?' . $query;
$url = match (Url::hasQuery($url)) {
true => $url . '&' . $query,
default => $url . '?' . $query
};
}
// remove the data array from the options

View file

@ -147,9 +147,7 @@ class Request
// this ensures that the response is only cached for
// unauthenticated visitors;
// https://github.com/getkirby/kirby/issues/4423#issuecomment-1166300526
if ($kirby) {
$kirby->response()->usesAuth(true);
}
$kirby?->response()->usesAuth(true);
if ($auth = $this->authString()) {
$type = Str::lower(Str::before($auth, ' '));
@ -292,7 +290,10 @@ class Request
$headers = [];
foreach (Environment::getGlobally() as $key => $value) {
if (substr($key, 0, 5) !== 'HTTP_' && substr($key, 0, 14) !== 'REDIRECT_HTTP_') {
if (
substr($key, 0, 5) !== 'HTTP_' &&
substr($key, 0, 14) !== 'REDIRECT_HTTP_'
) {
continue;
}

View file

@ -2,6 +2,8 @@
namespace Kirby\Http\Request;
use SensitiveParameter;
/**
* Base class for auth types
*
@ -22,8 +24,10 @@ abstract class Auth
/**
* Constructor
*/
public function __construct(string $data)
{
public function __construct(
#[SensitiveParameter]
string $data
) {
$this->data = $data;
}

View file

@ -4,6 +4,7 @@ namespace Kirby\Http\Request\Auth;
use Kirby\Http\Request\Auth;
use Kirby\Toolkit\Str;
use SensitiveParameter;
/**
* HTTP basic authentication data
@ -20,8 +21,10 @@ class BasicAuth extends Auth
protected string|null $password;
protected string|null $username;
public function __construct(string $data)
{
public function __construct(
#[SensitiveParameter]
string $data
) {
parent::__construct($data);
$this->credentials = base64_decode($data);

View file

@ -22,7 +22,7 @@ class Files
/**
* Sanitized array of all received files
*/
protected array $files;
protected array $files = [];
/**
* Creates a new Files object
@ -31,11 +31,7 @@ class Files
*/
public function __construct(array|null $files = null)
{
if ($files === null) {
$files = $_FILES;
}
$this->files = [];
$files ??= $_FILES;
foreach ($files as $key => $file) {
if (is_array($file['name'])) {

View file

@ -50,8 +50,13 @@ class Response
/**
* Creates a new response object
*/
public function __construct(string|array $body = '', string|null $type = null, int|null $code = null, array|null $headers = null, string|null $charset = null)
{
public function __construct(
string|array $body = '',
string|null $type = null,
int|null $code = null,
array|null $headers = null,
string|null $charset = null
) {
// array construction
if (is_array($body) === true) {
$params = $body;
@ -127,8 +132,11 @@ class Response
*
* @param array $props Custom overrides for response props (e.g. headers)
*/
public static function download(string $file, string|null $filename = null, array $props = []): static
{
public static function download(
string $file,
string|null $filename = null,
array $props = []
): static {
if (file_exists($file) === false) {
throw new Exception('The file could not be found');
}
@ -178,6 +186,7 @@ class Response
* @since 3.7.0
*
* @codeCoverageIgnore
* @todo Change return type to `never` once support for PHP 8.0 is dropped
*/
public static function go(string $url = '/', int $code = 302): void
{
@ -223,8 +232,12 @@ class Response
* Creates a json response with appropriate
* header and automatic conversion of arrays.
*/
public static function json(string|array $body = '', int|null $code = null, bool|null $pretty = null, array $headers = []): static
{
public static function json(
string|array $body = '',
int|null $code = null,
bool|null $pretty = null,
array $headers = []
): static {
if (is_array($body) === true) {
$body = json_encode($body, $pretty === true ? JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES : 0);
}

View file

@ -72,8 +72,12 @@ class Route
* Creates a new Route object for the given
* pattern(s), method(s) and the callback action
*/
public function __construct(string $pattern, string $method, Closure $action, array $attributes = [])
{
public function __construct(
string $pattern,
string $method,
Closure $action,
array $attributes = []
) {
$this->action = $action;
$this->attributes = $attributes;
$this->method = $method;

View file

@ -117,7 +117,10 @@ class Router
if ($callback) {
$result = $callback($route);
} else {
$result = $route?->action()->call($route, ...$route->arguments());
$result = $route->action()->call(
$route,
...$route->arguments()
);
}
$loop = false;
@ -139,8 +142,12 @@ class Router
* the routing action immediately
* @since 3.7.0
*/
public static function execute(string|null $path = null, string $method = 'GET', array $routes = [], Closure|null $callback = null)
{
public static function execute(
string|null $path = null,
string $method = 'GET',
array $routes = [],
Closure|null $callback = null
) {
return (new static($routes))->call($path, $method, $callback);
}
@ -150,8 +157,11 @@ class Router
* find matches and return all the found
* arguments in the path.
*/
public function find(string $path, string $method, array|null $ignore = null): Route|null
{
public function find(
string $path,
string $method,
array|null $ignore = null
): Route {
if (isset($this->routes[$method]) === false) {
throw new InvalidArgumentException('Invalid routing method: ' . $method, 400);
}
@ -163,7 +173,10 @@ class Router
$arguments = $route->parse($route->pattern(), $path);
if ($arguments !== false) {
if (empty($ignore) === true || in_array($route, $ignore) === false) {
if (
empty($ignore) === true ||
in_array($route, $ignore) === false
) {
return $this->route = $route;
}
}

View file

@ -5,6 +5,7 @@ namespace Kirby\Http;
use Kirby\Cms\App;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Toolkit\Properties;
use SensitiveParameter;
use Throwable;
/**
@ -226,7 +227,10 @@ class Uri
$domain .= $this->host;
if ($this->port !== null && in_array($this->port, [80, 443]) === false) {
if (
$this->port !== null &&
in_array($this->port, [80, 443]) === false
) {
$domain .= ':' . $this->port;
}
@ -326,8 +330,10 @@ class Uri
/**
* @return $this
*/
public function setPassword(string|null $password = null): static
{
public function setPassword(
#[SensitiveParameter]
string|null $password = null
): static {
$this->password = $password;
return $this;
}

View file

@ -30,7 +30,8 @@ class Url
*/
public static function __callStatic(string $method, array $arguments)
{
return (new Uri($arguments[0] ?? static::current()))->$method(...array_slice($arguments, 1));
$uri = new Uri($arguments[0] ?? static::current());
return $uri->$method(...array_slice($arguments, 1));
}
/**
@ -65,7 +66,11 @@ class Url
public static function fix(string|null $url = null): string|null
{
// make sure to not touch absolute urls
return (!preg_match('!^(https|http|ftp)\:\/\/!i', $url ?? '')) ? 'http://' . $url : $url;
if (!preg_match('!^(https|http|ftp)\:\/\/!i', $url ?? '')) {
return 'http://' . $url;
}
return $url;
}
/**
@ -93,7 +98,9 @@ class Url
// //example.com/uri
// http://example.com/uri, https://example.com/uri, ftp://example.com/uri
// mailto:example@example.com, geo:49.0158,8.3239?z=11
return $url !== null && preg_match('!^(//|[a-z0-9+-.]+://|mailto:|tel:|geo:)!i', $url) === 1;
return
$url !== null &&
preg_match('!^(//|[a-z0-9+-.]+://|mailto:|tel:|geo:)!i', $url) === 1;
}
/**
@ -127,8 +134,11 @@ class Url
/**
* Returns the path for the given url
*/
public static function path(string|array|null $url = null, bool $leadingSlash = false, bool $trailingSlash = false): string
{
public static function path(
string|array|null $url = null,
bool $leadingSlash = false,
bool $trailingSlash = false
): string {
return Url::toObject($url)->path()->toString($leadingSlash, $trailingSlash);
}
@ -151,8 +161,12 @@ class Url
/**
* Shortens the Url by removing all unnecessary parts
*/
public static function short(string|null $url = null, int $length = 0, bool $base = false, string $rep = '…'): string
{
public static function short(
string|null $url = null,
int $length = 0,
bool $base = false,
string $rep = '…'
): string {
$uri = static::toObject($url);
$uri->fragment = null;