Upgrade to 3.6.1

This commit is contained in:
Bastian Allgeier
2021-12-07 12:39:37 +01:00
parent 9fc43ea22c
commit 70b8439c49
134 changed files with 19987 additions and 1100 deletions

View File

@@ -3,7 +3,6 @@
namespace Kirby\Http;
use Kirby\Toolkit\Str;
use TrueBV\Punycode;
/**
* Handles Internationalized Domain Names
@@ -16,14 +15,26 @@ use TrueBV\Punycode;
*/
class Idn
{
/**
* Convert domain name from IDNA ASCII to Unicode
*
* @param string $domain
* @return string|false
*/
public static function decode(string $domain)
{
return (new Punycode())->decode($domain);
return idn_to_utf8($domain);
}
/**
* Convert domain name to IDNA ASCII form
*
* @param string $domain
* @return string|false
*/
public static function encode(string $domain)
{
return (new Punycode())->encode($domain);
return idn_to_ascii($domain);
}
/**

View File

@@ -43,7 +43,7 @@ class Query extends Obj
public function toString($questionMark = false): string
{
$query = http_build_query($this, null, '&', PHP_QUERY_RFC3986);
$query = http_build_query($this, '', '&', PHP_QUERY_RFC3986);
if (empty($query) === true) {
return '';

View File

@@ -174,7 +174,7 @@ class Request
*/
public function body()
{
return $this->body = $this->body ?? new Body();
return $this->body ??= new Body();
}
/**
@@ -220,7 +220,7 @@ class Request
$methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH'];
// the request method can be overwritten with a header
$methodOverride = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ?? null);
$methodOverride = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ?? '');
if ($method === null && in_array($methodOverride, $methods) === true) {
$method = $methodOverride;
@@ -269,7 +269,7 @@ class Request
*/
public function files()
{
return $this->files = $this->files ?? new Files();
return $this->files ??= new Files();
}
/**
@@ -379,7 +379,7 @@ class Request
*/
public function query()
{
return $this->query = $this->query ?? new Query();
return $this->query ??= new Query();
}
/**
@@ -407,6 +407,6 @@ class Request
return $this->url()->clone($props);
}
return $this->url = $this->url ?? Uri::current();
return $this->url ??= Uri::current();
}
}

View File

@@ -160,14 +160,14 @@ class Response
throw new Exception('The file could not be found');
}
$filename = $filename ?? basename($file);
$modified = filemtime($file);
$body = file_get_contents($file);
$size = strlen($body);
$filename ??= basename($file);
$modified = filemtime($file);
$body = file_get_contents($file);
$size = strlen($body);
$props = array_replace_recursive([
'body' => $body,
'type' => 'application/force-download',
'type' => F::mime($file),
'headers' => [
'Pragma' => 'public',
'Cache-Control' => 'no-cache, no-store, must-revalidate',
@@ -234,7 +234,7 @@ class Response
public static function json($body = '', ?int $code = null, ?bool $pretty = null, array $headers = [])
{
if (is_array($body) === true) {
$body = json_encode($body, $pretty === true ? JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES : null);
$body = json_encode($body, $pretty === true ? JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES : 0);
}
return new static([

View File

@@ -5,6 +5,7 @@ namespace Kirby\Http;
use Closure;
use Exception;
use InvalidArgumentException;
use Kirby\Toolkit\A;
/**
* @package Kirby Http
@@ -59,8 +60,11 @@ class Router
throw new InvalidArgumentException('Invalid route parameters');
}
$methods = array_map('trim', explode('|', strtoupper($props['method'] ?? 'GET')));
$patterns = is_array($props['pattern']) === false ? [$props['pattern']] : $props['pattern'];
$patterns = A::wrap($props['pattern']);
$methods = A::map(
explode('|', strtoupper($props['method'] ?? 'GET')),
'trim'
);
if ($methods === ['ALL']) {
$methods = array_keys($this->routes);
@@ -88,7 +92,7 @@ class Router
*/
public function call(string $path = null, string $method = 'GET', Closure $callback = null)
{
$path = $path ?? '';
$path ??= '';
$ignore = [];
$result = null;
$loop = true;

View File

@@ -92,6 +92,9 @@ class Server
*/
public static function sanitize(string $key, $value)
{
// make sure $value is not null
$value ??= '';
switch ($key) {
case 'SERVER_ADDR':
case 'SERVER_NAME':
@@ -100,7 +103,7 @@ class Server
$value = strip_tags($value);
$value = preg_replace('![^\w.:-]+!iu', '', $value);
$value = trim($value, '-');
$value = htmlspecialchars($value);
$value = htmlspecialchars($value, ENT_COMPAT);
break;
case 'SERVER_PORT':
case 'HTTP_X_FORWARDED_PORT':

View File

@@ -144,10 +144,10 @@ class Uri
// parse the path and extract params
if (empty($props['path']) === false) {
$extract = Params::extract($props['path']);
$props['params'] = $props['params'] ?? $extract['params'];
$props['path'] = $extract['path'];
$props['slash'] = $props['slash'] ?? $extract['slash'];
$extract = Params::extract($props['path']);
$props['params'] ??= $extract['params'];
$props['path'] = $extract['path'];
$props['slash'] ??= $extract['slash'];
}
$this->setProperties($this->props = $props);
@@ -246,8 +246,12 @@ class Uri
return static::$current;
}
$uri = Server::get('REQUEST_URI');
$uri = preg_replace('!^(http|https)\:\/\/' . Server::get('HTTP_HOST') . '!', '', $uri);
$uri = Server::get('REQUEST_URI') ?? '';
$uri = preg_replace(
'!^(http|https)\:\/\/' . Server::get('HTTP_HOST') . '!',
'',
$uri
);
$uri = parse_url('http://getkirby.com' . $uri);
$url = new static(array_merge([

View File

@@ -145,8 +145,8 @@ class Url
}
// build the full url
$path = ltrim($path, '/');
$home = $home ?? static::home();
$path = ltrim($path, '/');
$home ??= static::home();
if (empty($path) === true) {
return $home;
@@ -260,6 +260,9 @@ class Url
*/
public static function to(string $path = null, $options = null): string
{
// make sure $path is string
$path ??= '';
// keep relative urls
if (substr($path, 0, 2) === './' || substr($path, 0, 3) === '../') {
return $path;