Upgrade to 3.2.0
This commit is contained in:
@@ -10,8 +10,9 @@ use Kirby\Toolkit\Str;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Cookie
|
||||
{
|
||||
|
@@ -2,6 +2,15 @@
|
||||
|
||||
namespace Kirby\Http\Exceptions;
|
||||
|
||||
/**
|
||||
* NextRouteException
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class NextRouteException extends \Exception
|
||||
{
|
||||
}
|
||||
|
@@ -10,8 +10,9 @@ use Kirby\Toolkit\F;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Header
|
||||
{
|
||||
|
@@ -9,9 +9,9 @@ use TrueBV\Punycode;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Idn
|
||||
{
|
||||
|
@@ -2,13 +2,18 @@
|
||||
|
||||
namespace Kirby\Http;
|
||||
|
||||
use Kirby\Toolkit\Obj;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
* A wrapper around a URL params
|
||||
* that converts it into a Kirby Obj for easier
|
||||
* access of each param.
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Params extends Query
|
||||
{
|
||||
|
@@ -8,6 +8,12 @@ use Kirby\Toolkit\Str;
|
||||
/**
|
||||
* A wrapper around an URL path
|
||||
* that converts the path into a Kirby stack
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Path extends Collection
|
||||
{
|
||||
|
@@ -8,6 +8,12 @@ use Kirby\Toolkit\Obj;
|
||||
* A wrapper around a URL query string
|
||||
* that converts it into a Kirby Obj for easier
|
||||
* access of each query attribute.
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Query extends Obj
|
||||
{
|
||||
|
@@ -12,9 +12,9 @@ use Kirby\Toolkit\Str;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Remote
|
||||
{
|
||||
@@ -180,7 +180,7 @@ class Remote
|
||||
}
|
||||
|
||||
// do some request specific stuff
|
||||
switch ($action = strtoupper($this->options['method'])) {
|
||||
switch (strtoupper($this->options['method'])) {
|
||||
case 'POST':
|
||||
$this->curlopt[CURLOPT_POST] = true;
|
||||
$this->curlopt[CURLOPT_CUSTOMREQUEST] = 'POST';
|
||||
|
@@ -18,9 +18,9 @@ use Kirby\Toolkit\Str;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
@@ -62,18 +62,9 @@ class Request
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* The Method object is a tiny
|
||||
* wrapper around the request method
|
||||
* name, which will validate and sanitize
|
||||
* the given name and always return
|
||||
* its uppercase version.
|
||||
* The Method type
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* `$request->method()->name()`
|
||||
* `$request->method()->is('post')`
|
||||
*
|
||||
* @var Method
|
||||
* @var string
|
||||
*/
|
||||
protected $method;
|
||||
|
||||
@@ -137,7 +128,7 @@ class Request
|
||||
}
|
||||
|
||||
/**
|
||||
* Improved var_dump output
|
||||
* Improved `var_dump` output
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -165,7 +156,7 @@ class Request
|
||||
/**
|
||||
* Returns the Auth object if authentication is set
|
||||
*
|
||||
* @return BasicAuth|BearerAuth|null
|
||||
* @return Kirby\Http\Request\Auth\BasicAuth|Kirby\Http\Request\Auth\BearerAuth|null
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
@@ -191,9 +182,9 @@ class Request
|
||||
/**
|
||||
* Returns the Body object
|
||||
*
|
||||
* @return Body
|
||||
* @return Kirby\Http\Request\Body
|
||||
*/
|
||||
public function body(): Body
|
||||
public function body()
|
||||
{
|
||||
return $this->body = $this->body ?? new Body();
|
||||
}
|
||||
@@ -228,6 +219,16 @@ class Request
|
||||
return array_merge($this->body()->toArray(), $this->query()->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the domain
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function domain(): string
|
||||
{
|
||||
return $this->url()->domain();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a single file array
|
||||
* from the Files object by key
|
||||
@@ -243,9 +244,9 @@ class Request
|
||||
/**
|
||||
* Returns the Files object
|
||||
*
|
||||
* @return Files
|
||||
* @return Kirby\Cms\Files
|
||||
*/
|
||||
public function files(): Files
|
||||
public function files()
|
||||
{
|
||||
return $this->files = $this->files ?? new Files();
|
||||
}
|
||||
@@ -342,12 +343,20 @@ class Request
|
||||
return $this->url()->params();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to the Path object
|
||||
*/
|
||||
public function path()
|
||||
{
|
||||
return $this->url()->path();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Query object
|
||||
*
|
||||
* @return Query
|
||||
* @return Kirby\Http\Query
|
||||
*/
|
||||
public function query(): Query
|
||||
public function query()
|
||||
{
|
||||
return $this->query = $this->query ?? new Query();
|
||||
}
|
||||
@@ -369,9 +378,9 @@ class Request
|
||||
* the original object.
|
||||
*
|
||||
* @param array $props
|
||||
* @return Uri
|
||||
* @return Kirby\Http\Uri
|
||||
*/
|
||||
public function url(array $props = null): Uri
|
||||
public function url(array $props = null)
|
||||
{
|
||||
if ($props !== null) {
|
||||
return $this->url()->clone($props);
|
||||
|
@@ -10,9 +10,9 @@ namespace Kirby\Http\Request;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Body
|
||||
{
|
||||
|
@@ -12,15 +12,15 @@ namespace Kirby\Http\Request;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
trait Data
|
||||
{
|
||||
|
||||
/**
|
||||
* Improved var_dump output
|
||||
* Improved `var_dump` output
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -11,9 +11,9 @@ namespace Kirby\Http\Request;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Files
|
||||
{
|
||||
|
@@ -9,9 +9,9 @@ namespace Kirby\Http\Request;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Query
|
||||
{
|
||||
|
@@ -14,9 +14,9 @@ use Kirby\Toolkit\F;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Response
|
||||
{
|
||||
@@ -90,7 +90,7 @@ class Response
|
||||
}
|
||||
|
||||
/**
|
||||
* Improved var_dump() output
|
||||
* Improved `var_dump` output
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -3,14 +3,13 @@
|
||||
namespace Kirby\Http;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Route
|
||||
{
|
||||
@@ -107,7 +106,7 @@ class Route
|
||||
*
|
||||
* @return Closure
|
||||
*/
|
||||
public function action(): Closure
|
||||
public function action()
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
@@ -117,7 +116,7 @@ class Route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arguments()
|
||||
public function arguments(): array
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
@@ -159,7 +158,7 @@ class Route
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function next()
|
||||
public function next(): void
|
||||
{
|
||||
throw new Exceptions\NextRouteException('next');
|
||||
}
|
||||
|
@@ -2,15 +2,16 @@
|
||||
|
||||
namespace Kirby\Http;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Router
|
||||
{
|
||||
@@ -82,10 +83,12 @@ class Router
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $method
|
||||
* @param Closure|null $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function call(string $path = '', string $method = 'GET')
|
||||
public function call(string $path = null, string $method = 'GET', Closure $callback = null)
|
||||
{
|
||||
$path = $path ?? '';
|
||||
$ignore = [];
|
||||
$result = null;
|
||||
$loop = true;
|
||||
@@ -98,14 +101,19 @@ class Router
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $route->action()->call($route, ...$route->arguments());
|
||||
if ($callback) {
|
||||
$result = $callback($route);
|
||||
} else {
|
||||
$result = $route->action()->call($route, ...$route->arguments());
|
||||
}
|
||||
|
||||
$loop = false;
|
||||
} catch (Exceptions\NextRouteException $e) {
|
||||
$ignore[] = $route;
|
||||
}
|
||||
|
||||
if (is_a(static::$afterEach, 'Closure') === true) {
|
||||
(static::$afterEach)($route, $path, $method, $result);
|
||||
$result = (static::$afterEach)($route, $path, $method, $result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +129,7 @@ class Router
|
||||
* @param string $path
|
||||
* @param string $method
|
||||
* @param array $ignore
|
||||
* @return Route|null
|
||||
* @return Kirby\Http\Route|null
|
||||
*/
|
||||
public function find(string $path, string $method, array $ignore = null)
|
||||
{
|
||||
@@ -151,7 +159,7 @@ class Router
|
||||
* once Router::find() has been called
|
||||
* and only if a route was found.
|
||||
*
|
||||
* @return Route|null
|
||||
* @return Kirby\Http\Route|null
|
||||
*/
|
||||
public function route()
|
||||
{
|
||||
|
@@ -8,9 +8,9 @@ namespace Kirby\Http;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Server
|
||||
{
|
||||
|
@@ -5,16 +5,15 @@ namespace Kirby\Http;
|
||||
use Throwable;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Toolkit\Properties;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
* Uri builder class
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Uri
|
||||
{
|
||||
@@ -197,7 +196,7 @@ class Uri
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function auth()
|
||||
public function auth(): ?string
|
||||
{
|
||||
$auth = trim($this->username . ':' . $this->password);
|
||||
return $auth !== ':' ? $auth : null;
|
||||
@@ -207,28 +206,15 @@ class Uri
|
||||
* Returns the base url (scheme + host)
|
||||
* without trailing slash
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function base()
|
||||
public function base(): ?string
|
||||
{
|
||||
if (empty($this->host) === true || $this->host === '/') {
|
||||
return null;
|
||||
if ($domain = $this->domain()) {
|
||||
return $this->scheme ? $this->scheme . '://' . $domain : $domain;
|
||||
}
|
||||
|
||||
$auth = $this->auth();
|
||||
$base = $this->scheme ? $this->scheme . '://' : '';
|
||||
|
||||
if ($auth !== null) {
|
||||
$base .= $auth . '@';
|
||||
}
|
||||
|
||||
$base .= $this->host;
|
||||
|
||||
if ($this->port !== null && in_array($this->port, [80, 443]) === false) {
|
||||
$base .= ':' . $this->port;
|
||||
}
|
||||
|
||||
return $base;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +224,7 @@ class Uri
|
||||
* @param array $props
|
||||
* @return self
|
||||
*/
|
||||
public function clone(array $props = []): self
|
||||
public function clone(array $props = [])
|
||||
{
|
||||
$clone = clone $this;
|
||||
|
||||
@@ -254,13 +240,15 @@ class Uri
|
||||
* @param boolean $forwarded
|
||||
* @return self
|
||||
*/
|
||||
public static function current(array $props = [], bool $forwarded = false): self
|
||||
public static function current(array $props = [], bool $forwarded = false)
|
||||
{
|
||||
if (static::$current !== null) {
|
||||
return static::$current;
|
||||
}
|
||||
|
||||
$uri = parse_url('http://getkirby.com' . Server::get('REQUEST_URI'));
|
||||
$uri = Server::get('REQUEST_URI');
|
||||
$uri = str_replace(Server::get('HTTP_HOST'), '', $uri);
|
||||
$uri = parse_url('http://getkirby.com' . $uri);
|
||||
|
||||
$url = new static(array_merge([
|
||||
'scheme' => Server::https() === true ? 'https' : 'http',
|
||||
@@ -273,6 +261,33 @@ class Uri
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the domain without scheme, path or query
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function domain(): ?string
|
||||
{
|
||||
if (empty($this->host) === true || $this->host === '/') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$auth = $this->auth();
|
||||
$domain = '';
|
||||
|
||||
if ($auth !== null) {
|
||||
$domain .= $auth . '@';
|
||||
}
|
||||
|
||||
$domain .= $this->host;
|
||||
|
||||
if ($this->port !== null && in_array($this->port, [80, 443]) === false) {
|
||||
$domain .= ':' . $this->port;
|
||||
}
|
||||
|
||||
return $domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
@@ -303,7 +318,7 @@ class Uri
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function idn(): self
|
||||
public function idn()
|
||||
{
|
||||
if (empty($this->host) === false) {
|
||||
$this->setHost(Idn::decode($this->host));
|
||||
@@ -319,7 +334,7 @@ class Uri
|
||||
* @param bool $forwarded
|
||||
* @return string
|
||||
*/
|
||||
public static function index(array $props = [], bool $forwarded = false): self
|
||||
public static function index(array $props = [], bool $forwarded = false)
|
||||
{
|
||||
if (Server::cli() === true) {
|
||||
$path = null;
|
||||
@@ -371,17 +386,17 @@ class Uri
|
||||
* @param string $host
|
||||
* @return self
|
||||
*/
|
||||
public function setHost(string $host = null): self
|
||||
public function setHost(string $host = null)
|
||||
{
|
||||
$this->host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Params|string|array|null $path
|
||||
* @param Kirby\Http\Params|string|array|null $path
|
||||
* @return self
|
||||
*/
|
||||
public function setParams($params = null): self
|
||||
public function setParams($params = null)
|
||||
{
|
||||
$this->params = is_a($params, 'Kirby\Http\Params') === true ? $params : new Params($params);
|
||||
return $this;
|
||||
@@ -391,17 +406,17 @@ class Uri
|
||||
* @param string|null $password
|
||||
* @return self
|
||||
*/
|
||||
public function setPassword(string $password = null): self
|
||||
public function setPassword(string $password = null)
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Path|string|array|null $path
|
||||
* @param Kirby\Http\Path|string|array|null $path
|
||||
* @return self
|
||||
*/
|
||||
public function setPath($path = null): self
|
||||
public function setPath($path = null)
|
||||
{
|
||||
$this->path = is_a($path, 'Kirby\Http\Path') === true ? $path : new Path($path);
|
||||
return $this;
|
||||
@@ -411,7 +426,7 @@ class Uri
|
||||
* @param int|null $port
|
||||
* @return self
|
||||
*/
|
||||
public function setPort(int $port = null): self
|
||||
public function setPort(int $port = null)
|
||||
{
|
||||
if ($port === 0) {
|
||||
$port = null;
|
||||
@@ -428,10 +443,10 @@ class Uri
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array|null $query
|
||||
* @param Kirby\Http\Query|string|array|null $query
|
||||
* @return self
|
||||
*/
|
||||
public function setQuery($query = null): self
|
||||
public function setQuery($query = null)
|
||||
{
|
||||
$this->query = is_a($query, 'Kirby\Http\Query') === true ? $query : new Query($query);
|
||||
return $this;
|
||||
@@ -441,7 +456,7 @@ class Uri
|
||||
* @param string $scheme
|
||||
* @return self
|
||||
*/
|
||||
public function setScheme(string $scheme = null): self
|
||||
public function setScheme(string $scheme = null)
|
||||
{
|
||||
if ($scheme !== null && in_array($scheme, ['http', 'https', 'ftp']) === false) {
|
||||
throw new InvalidArgumentException('Invalid URL scheme: ' . $scheme);
|
||||
@@ -458,7 +473,7 @@ class Uri
|
||||
* @param bool $slash
|
||||
* @return self
|
||||
*/
|
||||
public function setSlash(bool $slash = false): self
|
||||
public function setSlash(bool $slash = false)
|
||||
{
|
||||
$this->slash = $slash;
|
||||
return $this;
|
||||
@@ -468,7 +483,7 @@ class Uri
|
||||
* @param string|null $username
|
||||
* @return self
|
||||
*/
|
||||
public function setUsername(string $username = null): self
|
||||
public function setUsername(string $username = null)
|
||||
{
|
||||
$this->username = $username;
|
||||
return $this;
|
||||
@@ -538,7 +553,7 @@ class Uri
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function unIdn(): self
|
||||
public function unIdn()
|
||||
{
|
||||
if (empty($this->host) === false) {
|
||||
$this->setHost(Idn::encode($this->host));
|
||||
|
@@ -2,11 +2,16 @@
|
||||
|
||||
namespace Kirby\Http;
|
||||
|
||||
use Exception;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
* Static URL tools
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Url
|
||||
{
|
||||
@@ -16,7 +21,7 @@ class Url
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $home = '/';
|
||||
public static $home = '/';
|
||||
|
||||
/**
|
||||
* The current Uri object
|
||||
@@ -47,7 +52,7 @@ class Url
|
||||
*/
|
||||
public static function build(array $parts = [], string $url = null): string
|
||||
{
|
||||
return (new Uri($url ?? static::current()))->clone($parts);
|
||||
return (string)(new Uri($url ?? static::current()))->clone($parts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +81,7 @@ class Url
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
public static function fix(string $url = null)
|
||||
public static function fix(string $url = null): string
|
||||
{
|
||||
// make sure to not touch absolute urls
|
||||
return (!preg_match('!^(https|http|ftp)\:\/\/!i', $url)) ? 'http://' . $url : $url;
|
||||
@@ -125,7 +130,7 @@ class Url
|
||||
* @param string $home
|
||||
* @return string
|
||||
*/
|
||||
public static function makeAbsolute(string $path = null, string $home = null)
|
||||
public static function makeAbsolute(string $path = null, string $home = null): string
|
||||
{
|
||||
if ($path === '' || $path === '/' || $path === null) {
|
||||
return $home ?? static::home();
|
||||
@@ -156,7 +161,7 @@ class Url
|
||||
* @param string|array|null $url
|
||||
* @param bool $leadingSlash
|
||||
* @param bool $trailingSlash
|
||||
* @return mixed
|
||||
* @return xtring
|
||||
*/
|
||||
public static function path($url = null, bool $leadingSlash = false, bool $trailingSlash = false): string
|
||||
{
|
||||
@@ -167,7 +172,7 @@ class Url
|
||||
* Returns the query for the given url
|
||||
*
|
||||
* @param string|array|null $url
|
||||
* @return mixed
|
||||
* @return string
|
||||
*/
|
||||
public static function query($url = null): string
|
||||
{
|
||||
@@ -188,12 +193,12 @@ class Url
|
||||
* Shortens the Url by removing all unnecessary parts
|
||||
*
|
||||
* @param string $url
|
||||
* @param boolean $length
|
||||
* @param int $length
|
||||
* @param boolean $base
|
||||
* @param string $rep
|
||||
* @return string
|
||||
*/
|
||||
public static function short($url = null, $length = false, bool $base = false, string $rep = '…'): string
|
||||
public static function short($url = null, int $length = 0, bool $base = false, string $rep = '…'): string
|
||||
{
|
||||
$uri = static::toObject($url);
|
||||
|
||||
@@ -250,7 +255,7 @@ class Url
|
||||
* Smart resolver for internal and external urls
|
||||
*
|
||||
* @param string $path
|
||||
* @param $options
|
||||
* @param mixed $options
|
||||
* @return string
|
||||
*/
|
||||
public static function to(string $path = null, $options = null): string
|
||||
@@ -273,7 +278,7 @@ class Url
|
||||
* Converts the Url to a Uri object
|
||||
*
|
||||
* @param string $url
|
||||
* @return Uri
|
||||
* @return Kirby\Http\Uri
|
||||
*/
|
||||
public static function toObject($url = null)
|
||||
{
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Kirby\Http;
|
||||
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\Collection;
|
||||
use Kirby\Toolkit\Mime;
|
||||
use Kirby\Toolkit\Obj;
|
||||
@@ -15,9 +14,9 @@ use Kirby\Toolkit\Str;
|
||||
*
|
||||
* @package Kirby Http
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link http://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Visitor
|
||||
{
|
||||
@@ -69,7 +68,7 @@ class Visitor
|
||||
* accepted language otherwise
|
||||
*
|
||||
* @param string|null $acceptedLanguage
|
||||
* @return Obj|Visitor|null
|
||||
* @return Kirby\Toolkit\Obj|Kirby\Http\Visitor|null
|
||||
*/
|
||||
public function acceptedLanguage(string $acceptedLanguage = null)
|
||||
{
|
||||
@@ -85,7 +84,7 @@ class Visitor
|
||||
* Returns an array of all accepted languages
|
||||
* including their quality and locale
|
||||
*
|
||||
* @return Collection
|
||||
* @return Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function acceptedLanguages()
|
||||
{
|
||||
@@ -136,7 +135,7 @@ class Visitor
|
||||
* accepted mime type otherwise
|
||||
*
|
||||
* @param string|null $acceptedMimeType
|
||||
* @return Obj|Visitor
|
||||
* @return Kirby\Toolkit\Obj|Kirby\Http\Visitor
|
||||
*/
|
||||
public function acceptedMimeType(string $acceptedMimeType = null)
|
||||
{
|
||||
@@ -151,7 +150,7 @@ class Visitor
|
||||
/**
|
||||
* Returns a collection of all accepted mime types
|
||||
*
|
||||
* @return Collection
|
||||
* @return Kirby\Toolkit\Collection
|
||||
*/
|
||||
public function acceptedMimeTypes()
|
||||
{
|
||||
|
Reference in New Issue
Block a user