Update Kirby and dependencies

This commit is contained in:
Paul Nicoué 2022-06-17 18:02:55 +02:00
parent 750b9cc83e
commit 8c71a258b6
59 changed files with 2143 additions and 813 deletions

View file

@ -268,7 +268,14 @@ class Server
public static function requestUri(): array
{
$uri = static::get('REQUEST_URI', '');
$uri = parse_url($uri);
if (Url::isAbsolute($uri) === true) {
$uri = parse_url($uri);
} else {
// the fake domain is needed to make sure the URL parsing is
// always correct. Even if there's a colon in the path for params
$uri = parse_url('http://getkirby.com' . $uri);
}
return [
'path' => $uri['path'] ?? null,

View file

@ -130,7 +130,7 @@ class Uri
* Creates a new URI object
*
* @param array|string $props
* @param array $inject
* @param array $inject Additional props to inject if a URL string is passed
*/
public function __construct($props = [], array $inject = [])
{
@ -144,10 +144,7 @@ class Uri
// parse the path and extract params
if (empty($props['path']) === false) {
$extract = Params::extract($props['path']);
$props['params'] ??= $extract['params'];
$props['path'] = $extract['path'];
$props['slash'] ??= $extract['slash'];
$props = static::parsePath($props);
}
$this->setProperties($this->props = $props);
@ -372,11 +369,17 @@ class Uri
}
/**
* @param \Kirby\Http\Params|string|array|null $params
* @param \Kirby\Http\Params|string|array|false|null $params
* @return $this
*/
public function setParams($params = null)
{
// ensure that the special constructor value of `false`
// is never passed through as it's not supported by `Params`
if ($params === false) {
$params = [];
}
$this->params = is_a($params, 'Kirby\Http\Params') === true ? $params : new Params($params);
return $this;
}
@ -539,4 +542,33 @@ class Uri
}
return $this;
}
/**
* Parses the path inside the props and extracts
* the params unless disabled
*
* @param array $props
* @return array Modified props array
*/
protected static function parsePath(array $props): array
{
// extract params, the rest is the path;
// only do this if not explicitly disabled (set to `false`)
if (isset($props['params']) === false || $props['params'] !== false) {
$extract = Params::extract($props['path']);
$props['params'] ??= $extract['params'];
$props['path'] = $extract['path'];
$props['slash'] ??= $extract['slash'];
return $props;
}
// use the full path;
// automatically detect the trailing slash from it if possible
if (is_string($props['path']) === true) {
$props['slash'] = substr($props['path'], -1, 1) === '/';
}
return $props;
}
}