Upgrade to 3.8.0
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Kirby\Http;
|
||||
|
||||
use Kirby\Toolkit\Obj;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
@@ -15,19 +16,14 @@ use Kirby\Toolkit\Str;
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Params extends Query
|
||||
class Params extends Obj
|
||||
{
|
||||
/**
|
||||
* @var null|string
|
||||
*/
|
||||
public static $separator;
|
||||
public static string|null $separator = null;
|
||||
|
||||
/**
|
||||
* Creates a new params object
|
||||
*
|
||||
* @param array|string $params
|
||||
*/
|
||||
public function __construct($params)
|
||||
public function __construct(array|string|null $params)
|
||||
{
|
||||
if (is_string($params) === true) {
|
||||
$params = static::extract($params)['params'];
|
||||
@@ -38,11 +34,8 @@ class Params extends Query
|
||||
|
||||
/**
|
||||
* Extract the params from a string or array
|
||||
*
|
||||
* @param string|array|null $path
|
||||
* @return array
|
||||
*/
|
||||
public static function extract($path = null): array
|
||||
public static function extract(string|array|null $path = null): array
|
||||
{
|
||||
if (empty($path) === true) {
|
||||
return [
|
||||
@@ -93,14 +86,22 @@ class Params extends Query
|
||||
];
|
||||
}
|
||||
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
return empty((array)$this) === true;
|
||||
}
|
||||
|
||||
public function isNotEmpty(): bool
|
||||
{
|
||||
return empty((array)$this) === false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the param separator according
|
||||
* to the operating system.
|
||||
*
|
||||
* Unix = ':'
|
||||
* Windows = ';'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function separator(): string
|
||||
{
|
||||
@@ -110,26 +111,16 @@ class Params extends Query
|
||||
|
||||
if (DIRECTORY_SEPARATOR === '/') {
|
||||
return static::$separator = ':';
|
||||
} else {
|
||||
return static::$separator = ';';
|
||||
}
|
||||
|
||||
return static::$separator = ';';
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the params object to a params string
|
||||
* which can then be used in the URL builder again
|
||||
*
|
||||
* @param bool $leadingSlash
|
||||
* @param bool $trailingSlash
|
||||
* @return string|null
|
||||
*
|
||||
* @todo The argument $leadingSlash is incompatible with
|
||||
* Query::toString($questionMark = false); the Query class
|
||||
* should be extracted into a common parent class for both
|
||||
* Query and Params
|
||||
* @psalm-suppress ParamNameMismatch
|
||||
*/
|
||||
public function toString($leadingSlash = false, $trailingSlash = false): string
|
||||
public function toString(bool $leadingSlash = false, bool $trailingSlash = false): string
|
||||
{
|
||||
if ($this->isEmpty() === true) {
|
||||
return '';
|
||||
@@ -155,4 +146,9 @@ class Params extends Query
|
||||
|
||||
return $leadingSlash . $params . $trailingSlash;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user