Upgrade to 3.3.0

This commit is contained in:
Bastian Allgeier
2019-11-05 09:35:58 +01:00
parent 447a9dd266
commit a431716732
186 changed files with 3068 additions and 1458 deletions

View File

@@ -32,12 +32,12 @@ class Cookie
*
* </code>
*
* @param string $key The name of the cookie
* @param string $value The cookie content
* @param array $options Array of options:
* lifetime, path, domain, secure, httpOnly
* @return boolean true: cookie was created,
* false: cookie creation failed
* @param string $key The name of the cookie
* @param string $value The cookie content
* @param array $options Array of options:
* lifetime, path, domain, secure, httpOnly
* @return bool true: cookie was created,
* false: cookie creation failed
*/
public static function set(string $key, string $value, array $options = []): bool
{
@@ -61,7 +61,7 @@ class Cookie
/**
* Calculates the lifetime for a cookie
*
* @param int $minutes Number of minutes or timestamp
* @param int $minutes Number of minutes or timestamp
* @return int
*/
public static function lifetime(int $minutes): int
@@ -87,12 +87,12 @@ class Cookie
*
* </code>
*
* @param string $key The name of the cookie
* @param string $value The cookie content
* @param array $options Array of options:
* path, domain, secure, httpOnly
* @return boolean true: cookie was created,
* false: cookie creation failed
* @param string $key The name of the cookie
* @param string $value The cookie content
* @param array $options Array of options:
* path, domain, secure, httpOnly
* @return bool true: cookie was created,
* false: cookie creation failed
*/
public static function forever(string $key, string $value, array $options = []): bool
{
@@ -110,10 +110,10 @@ class Cookie
*
* </code>
*
* @param string|null $key The name of the cookie
* @param string|null $default The default value, which should be returned
* if the cookie has not been found
* @return mixed The found value
* @param string|null $key The name of the cookie
* @param string|null $default The default value, which should be returned
* if the cookie has not been found
* @return mixed The found value
*/
public static function get(string $key = null, string $default = null)
{
@@ -127,8 +127,8 @@ class Cookie
/**
* Checks if a cookie exists
*
* @param string $key
* @return boolean
* @param string $key
* @return bool
*/
public static function exists(string $key): bool
{
@@ -139,7 +139,7 @@ class Cookie
* Creates a HMAC for the cookie value
* Used as a cookie signature to prevent easy tampering with cookie data
*
* @param string $value
* @param string $value
* @return string
*/
protected static function hmac(string $value): string
@@ -151,7 +151,7 @@ class Cookie
* Parses the hashed value from a cookie
* and tries to extract the value
*
* @param string $string
* @param string $string
* @return mixed
*/
protected static function parse(string $string)
@@ -190,9 +190,9 @@ class Cookie
*
* </code>
*
* @param string $key The name of the cookie
* @return boolean true: the cookie has been removed,
* false: the cookie could not be removed
* @param string $key The name of the cookie
* @return bool true: the cookie has been removed,
* false: the cookie could not be removed
*/
public static function remove(string $key): bool
{

View File

@@ -58,7 +58,7 @@ class Header
*
* @param string $mime
* @param string $charset
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function contentType(string $mime, string $charset = 'UTF-8', bool $send = true)
@@ -108,7 +108,7 @@ class Header
*
* @param string $mime
* @param string $charset
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function type(string $mime, string $charset = 'UTF-8', bool $send = true)
@@ -124,7 +124,7 @@ class Header
* as 3 digits followed by a space and a message, e.g. '999 Custom Status'.
*
* @param int|string $code The HTTP status code
* @param boolean $send If set to false the header will be returned instead
* @param bool $send If set to false the header will be returned instead
* @return string|void
*/
public static function status($code = null, bool $send = true)
@@ -154,7 +154,7 @@ class Header
/**
* Sends a 200 header
*
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function success(bool $send = true)
@@ -165,7 +165,7 @@ class Header
/**
* Sends a 201 header
*
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function created(bool $send = true)
@@ -176,7 +176,7 @@ class Header
/**
* Sends a 202 header
*
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function accepted(bool $send = true)
@@ -187,7 +187,7 @@ class Header
/**
* Sends a 400 header
*
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function error(bool $send = true)
@@ -198,7 +198,7 @@ class Header
/**
* Sends a 403 header
*
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function forbidden(bool $send = true)
@@ -209,7 +209,7 @@ class Header
/**
* Sends a 404 header
*
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function notfound(bool $send = true)
@@ -220,7 +220,7 @@ class Header
/**
* Sends a 404 header
*
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function missing(bool $send = true)
@@ -231,7 +231,7 @@ class Header
/**
* Sends a 410 header
*
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function gone(bool $send = true)
@@ -242,7 +242,7 @@ class Header
/**
* Sends a 500 header
*
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function panic(bool $send = true)
@@ -253,7 +253,7 @@ class Header
/**
* Sends a 503 header
*
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function unavailable(bool $send = true)
@@ -266,7 +266,7 @@ class Header
*
* @param string $url
* @param int $code
* @param boolean $send
* @param bool $send
* @return string|void
*/
public static function redirect(string $url, int $code = 302, bool $send = true)

View File

@@ -116,8 +116,8 @@ class Params extends Query
* Converts the params object to a params string
* which can then be used in the URL builder again
*
* @param boolean $leadingSlash
* @param boolean $trailingSlash
* @param bool $leadingSlash
* @param bool $trailingSlash
* @return string|null
*/
public function toString($leadingSlash = false, $trailingSlash = false): string

View File

@@ -113,7 +113,7 @@ class Remote
/**
* Returns the http status code
*
* @return integer|null
* @return int|null
*/
public function code(): ?int
{

View File

@@ -142,16 +142,6 @@ class Request
];
}
/**
* Detects ajax requests
* @deprecated 3.1.0 No longer reliable, especially with the fetch api.
* @return boolean
*/
public function ajax(): bool
{
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
}
/**
* Returns the Auth object if authentication is set
*
@@ -191,7 +181,7 @@ class Request
/**
* Checks if the request has been made from the command line
*
* @return boolean
* @return bool
*/
public function cli(): bool
{
@@ -232,7 +222,7 @@ class Request
* Fetches a single file array
* from the Files object by key
*
* @param string $key
* @param string $key
* @return array|null
*/
public function file(string $key)
@@ -316,8 +306,8 @@ class Request
* Checks if the given method name
* matches the name of the request method.
*
* @param string $method
* @return boolean
* @param string $method
* @return bool
*/
public function is(string $method): bool
{
@@ -363,7 +353,7 @@ class Request
/**
* Checks for a valid SSL connection
*
* @return boolean
* @return bool
*/
public function ssl(): bool
{

View File

@@ -44,8 +44,8 @@ trait Data
* of the data array by key or multiple values by
* passing an array of keys.
*
* @param string|array $key
* @param mixed|null $default
* @param string|array $key
* @param mixed|null $default
* @return mixed
*/
public function get($key, $default = null)

View File

@@ -58,11 +58,11 @@ class Response
/**
* Creates a new response object
*
* @param string $body
* @param string $type
* @param integer $code
* @param array $headers
* @param string $charset
* @param string $body
* @param string $type
* @param int $code
* @param array $headers
* @param string $charset
*/
public function __construct($body = '', ?string $type = null, ?int $code = null, ?array $headers = null, ?string $charset = null)
{
@@ -194,7 +194,7 @@ class Response
/**
* Getter for single headers
*
* @param string $key Name of the header
* @param string $key Name of the header
* @return string|null
*/
public function header(string $key): ?string
@@ -217,8 +217,8 @@ class Response
* header and automatic conversion of arrays.
*
* @param string|array $body
* @param integer $code
* @param boolean $pretty
* @param int $code
* @param bool $pretty
* @param array $headers
* @return self
*/
@@ -242,7 +242,7 @@ class Response
* given location.
*
* @param string $location
* @param integer $code
* @param int $code
* @return self
*/
public static function redirect(?string $location = null, ?int $code = null)

View File

@@ -90,7 +90,7 @@ class Route
*
* @param string|array $pattern
* @param string|array $method
* @param Closure $action
* @param Closure $action
* @param array $attributes
*/
public function __construct($pattern, $method = 'GET', Closure $action, array $attributes = [])
@@ -177,7 +177,7 @@ class Route
* Converts the pattern into a full regular
* expression by replacing all the wildcards
*
* @param string $pattern
* @param string $pattern
* @return string
*/
public function regex(string $pattern): string
@@ -201,8 +201,8 @@ class Route
* Tries to match the path with the regular expression and
* extracts all arguments for the Route action
*
* @param string $pattern
* @param string $path
* @param string $pattern
* @param string $path
* @return array|false
*/
public function parse(string $pattern, string $path)

View File

@@ -81,9 +81,9 @@ class Router
* the appropriate arguments and a Result
* object.
*
* @param string $path
* @param string $method
* @param Closure|null $callback
* @param string $path
* @param string $method
* @param Closure|null $callback
* @return mixed
*/
public function call(string $path = null, string $method = 'GET', Closure $callback = null)
@@ -126,9 +126,9 @@ class Router
* find matches and return all the found
* arguments in the path.
*
* @param string $path
* @param string $method
* @param array $ignore
* @param string $path
* @param string $method
* @param array $ignore
* @return \Kirby\Http\Route|null
*/
public function find(string $path, string $method, array $ignore = null)

View File

@@ -34,7 +34,7 @@ class Server
/**
* Checks if the request is being served by the CLI
*
* @return boolean
* @return bool
*/
public static function cli(): bool
{
@@ -66,10 +66,10 @@ class Server
* // returns the whole server array
* </code>
*
* @param mixed $key The key to look for. Pass false or null to
* return the entire server array.
* @param mixed $default Optional default value, which should be
* returned if no element has been found
* @param mixed $key The key to look for. Pass false or null to
* return the entire server array.
* @param mixed $default Optional default value, which should be
* returned if no element has been found
* @return mixed
*/
public static function get($key = null, $default = null)
@@ -86,8 +86,8 @@ class Server
/**
* Help to sanitize some _SERVER keys
*
* @param string $key
* @param mixed $value
* @param string $key
* @param mixed $value
* @return mixed
*/
public static function sanitize(string $key, $value)
@@ -131,7 +131,7 @@ class Server
/**
* Checks for a https request
*
* @return boolean
* @return bool
*/
public static function https(): bool
{

View File

@@ -90,7 +90,7 @@ class Uri
protected $scheme = 'http';
/**
* @var boolean
* @var bool
*/
protected $slash = false;
@@ -237,7 +237,7 @@ class Uri
/**
* @param array $props
* @param boolean $forwarded
* @param bool $forwarded
* @return self
*/
public static function current(array $props = [], bool $forwarded = false)
@@ -289,7 +289,7 @@ class Uri
}
/**
* @return boolean
* @return bool
*/
public function hasFragment(): bool
{
@@ -297,7 +297,7 @@ class Uri
}
/**
* @return boolean
* @return bool
*/
public function hasPath(): bool
{
@@ -305,7 +305,7 @@ class Uri
}
/**
* @return boolean
* @return bool
*/
public function hasQuery(): bool
{
@@ -373,7 +373,7 @@ class Uri
}
/**
* @param string|null $fragment
* @param string|null $fragment
* @return self
*/
public function setFragment(string $fragment = null)
@@ -383,7 +383,7 @@ class Uri
}
/**
* @param string $host
* @param string $host
* @return self
*/
public function setHost(string $host = null)
@@ -393,7 +393,7 @@ class Uri
}
/**
* @param Kirby\Http\Params|string|array|null $params
* @param \Kirby\Http\Params|string|array|null $params
* @return self
*/
public function setParams($params = null)
@@ -403,7 +403,7 @@ class Uri
}
/**
* @param string|null $password
* @param string|null $password
* @return self
*/
public function setPassword(string $password = null)
@@ -453,7 +453,7 @@ class Uri
}
/**
* @param string $scheme
* @param string $scheme
* @return self
*/
public function setScheme(string $scheme = null)
@@ -480,7 +480,7 @@ class Uri
}
/**
* @param string|null $username
* @param string|null $username
* @return self
*/
public function setUsername(string $username = null)

View File

@@ -112,7 +112,7 @@ class Url
* Checks if an URL is absolute
*
* @param string $url
* @return boolean
* @return bool
*/
public static function isAbsolute(string $url = null): bool
{
@@ -194,7 +194,7 @@ class Url
*
* @param string $url
* @param int $length
* @param boolean $base
* @param bool $base
* @param string $rep
* @return string
*/

View File

@@ -66,7 +66,7 @@ class Visitor
* provided or returns the user's
* accepted language otherwise
*
* @param string|null $acceptedLanguage
* @param string|null $acceptedLanguage
* @return \Kirby\Toolkit\Obj|\Kirby\Http\Visitor|null
*/
public function acceptedLanguage(string $acceptedLanguage = null)
@@ -133,7 +133,7 @@ class Visitor
* provided or returns the user's
* accepted mime type otherwise
*
* @param string|null $acceptedMimeType
* @param string|null $acceptedMimeType
* @return \Kirby\Toolkit\Obj|\Kirby\Http\Visitor
*/
public function acceptedMimeType(string $acceptedMimeType = null)
@@ -169,20 +169,57 @@ class Visitor
/**
* Checks if the user accepts the given mime type
*
* @param string $mimeType
* @return boolean
* @param string $mimeType
* @return bool
*/
public function acceptsMimeType(string $mimeType): bool
{
return Mime::isAccepted($mimeType, $this->acceptedMimeType);
}
/**
* Returns the MIME type from the provided list that
* is most accepted (= preferred) by the visitor
*
* @param string ...$mimeTypes MIME types to query for
* @return string|null Preferred MIME type
*/
public function preferredMimeType(string ...$mimeTypes): ?string
{
foreach ($this->acceptedMimeTypes() as $acceptedMime) {
// look for direct matches
if (in_array($acceptedMime->type(), $mimeTypes)) {
return $acceptedMime->type();
}
// test each option against wildcard `Accept` values
foreach ($mimeTypes as $expectedMime) {
if (Mime::matches($expectedMime, $acceptedMime->type()) === true) {
return $expectedMime;
}
}
}
return null;
}
/**
* Returns true if the visitor prefers a JSON response over
* an HTML response based on the `Accept` request header
*
* @return bool
*/
public function prefersJson(): bool
{
return $this->preferredMimeType('application/json', 'text/html') === 'application/json';
}
/**
* Sets the ip address if provided
* or returns the ip of the current
* visitor otherwise
*
* @param string|null $ip
* @param string|null $ip
* @return string|Visitor|null
*/
public function ip(string $ip = null)
@@ -199,7 +236,7 @@ class Visitor
* or returns the user agent string of
* the current visitor otherwise
*
* @param string|null $userAgent
* @param string|null $userAgent
* @return string|Visitor|null
*/
public function userAgent(string $userAgent = null)