Upgrade to 3.7.1

This commit is contained in:
Bastian Allgeier
2022-07-12 13:33:21 +02:00
parent 7931eb5e47
commit 1ad1eaf387
377 changed files with 63981 additions and 63824 deletions

View File

@@ -13,49 +13,49 @@ namespace Kirby\Http\Request;
*/
abstract class Auth
{
/**
* Raw authentication data after the first space
* in the `Authorization` header
*
* @var string
*/
protected $data;
/**
* Raw authentication data after the first space
* in the `Authorization` header
*
* @var string
*/
protected $data;
/**
* Constructor
*
* @param string $data
*/
public function __construct(string $data)
{
$this->data = $data;
}
/**
* Constructor
*
* @param string $data
*/
public function __construct(string $data)
{
$this->data = $data;
}
/**
* Converts the object to a string
*
* @return string
*/
public function __toString(): string
{
return ucfirst($this->type()) . ' ' . $this->data();
}
/**
* Converts the object to a string
*
* @return string
*/
public function __toString(): string
{
return ucfirst($this->type()) . ' ' . $this->data();
}
/**
* Returns the raw authentication data after the
* first space in the `Authorization` header
*
* @return string
*/
public function data(): string
{
return $this->data;
}
/**
* Returns the raw authentication data after the
* first space in the `Authorization` header
*
* @return string
*/
public function data(): string
{
return $this->data;
}
/**
* Returns the name of the auth type (lowercase)
*
* @return string
*/
abstract public function type(): string;
/**
* Returns the name of the auth type (lowercase)
*
* @return string
*/
abstract public function type(): string;
}

View File

@@ -16,70 +16,70 @@ use Kirby\Toolkit\Str;
*/
class BasicAuth extends Auth
{
/**
* @var string
*/
protected $credentials;
/**
* @var string
*/
protected $credentials;
/**
* @var string
*/
protected $password;
/**
* @var string
*/
protected $password;
/**
* @var string
*/
protected $username;
/**
* @var string
*/
protected $username;
/**
* @param string $token
*/
public function __construct(string $data)
{
parent::__construct($data);
/**
* @param string $token
*/
public function __construct(string $data)
{
parent::__construct($data);
$this->credentials = base64_decode($data);
$this->username = Str::before($this->credentials, ':');
$this->password = Str::after($this->credentials, ':');
}
$this->credentials = base64_decode($data);
$this->username = Str::before($this->credentials, ':');
$this->password = Str::after($this->credentials, ':');
}
/**
* Returns the entire unencoded credentials string
*
* @return string
*/
public function credentials(): string
{
return $this->credentials;
}
/**
* Returns the entire unencoded credentials string
*
* @return string
*/
public function credentials(): string
{
return $this->credentials;
}
/**
* Returns the password
*
* @return string|null
*/
public function password(): ?string
{
return $this->password;
}
/**
* Returns the password
*
* @return string|null
*/
public function password(): ?string
{
return $this->password;
}
/**
* Returns the authentication type
*
* @return string
*/
public function type(): string
{
return 'basic';
}
/**
* Returns the authentication type
*
* @return string
*/
public function type(): string
{
return 'basic';
}
/**
* Returns the username
*
* @return string|null
*/
public function username(): ?string
{
return $this->username;
}
/**
* Returns the username
*
* @return string|null
*/
public function username(): ?string
{
return $this->username;
}
}

View File

@@ -15,23 +15,23 @@ use Kirby\Http\Request\Auth;
*/
class BearerAuth extends Auth
{
/**
* Returns the authentication token
*
* @return string
*/
public function token(): string
{
return $this->data;
}
/**
* Returns the authentication token
*
* @return string
*/
public function token(): string
{
return $this->data;
}
/**
* Returns the auth type
*
* @return string
*/
public function type(): string
{
return 'bearer';
}
/**
* Returns the auth type
*
* @return string
*/
public function type(): string
{
return 'bearer';
}
}

View File

@@ -16,33 +16,33 @@ use Kirby\Http\Request\Auth;
*/
class SessionAuth extends Auth
{
/**
* Tries to return the session object
*
* @return \Kirby\Session\Session
*/
public function session()
{
return App::instance()->sessionHandler()->getManually($this->data);
}
/**
* Tries to return the session object
*
* @return \Kirby\Session\Session
*/
public function session()
{
return App::instance()->sessionHandler()->getManually($this->data);
}
/**
* Returns the session token
*
* @return string
*/
public function token(): string
{
return $this->data;
}
/**
* Returns the session token
*
* @return string
*/
public function token(): string
{
return $this->data;
}
/**
* Returns the authentication type
*
* @return string
*/
public function type(): string
{
return 'session';
}
/**
* Returns the authentication type
*
* @return string
*/
public function type(): string
{
return 'session';
}
}

View File

@@ -16,114 +16,114 @@ namespace Kirby\Http\Request;
*/
class Body
{
use Data;
use Data;
/**
* The raw body content
*
* @var string|array
*/
protected $contents;
/**
* The raw body content
*
* @var string|array
*/
protected $contents;
/**
* The parsed content as array
*
* @var array
*/
protected $data;
/**
* The parsed content as array
*
* @var array
*/
protected $data;
/**
* Creates a new request body object.
* You can pass your own array or string.
* If null is being passed, the class will
* fetch the body either from the $_POST global
* or from php://input.
*
* @param array|string|null $contents
*/
public function __construct($contents = null)
{
$this->contents = $contents;
}
/**
* Creates a new request body object.
* You can pass your own array or string.
* If null is being passed, the class will
* fetch the body either from the $_POST global
* or from php://input.
*
* @param array|string|null $contents
*/
public function __construct($contents = null)
{
$this->contents = $contents;
}
/**
* Fetches the raw contents for the body
* or uses the passed contents.
*
* @return string|array
*/
public function contents()
{
if ($this->contents === null) {
if (empty($_POST) === false) {
$this->contents = $_POST;
} else {
$this->contents = file_get_contents('php://input');
}
}
/**
* Fetches the raw contents for the body
* or uses the passed contents.
*
* @return string|array
*/
public function contents()
{
if ($this->contents === null) {
if (empty($_POST) === false) {
$this->contents = $_POST;
} else {
$this->contents = file_get_contents('php://input');
}
}
return $this->contents;
}
return $this->contents;
}
/**
* Parses the raw contents once and caches
* the result. The parser will try to convert
* the body with the json decoder first and
* then run parse_str to get some results
* if the json decoder failed.
*
* @return array
*/
public function data(): array
{
if (is_array($this->data) === true) {
return $this->data;
}
/**
* Parses the raw contents once and caches
* the result. The parser will try to convert
* the body with the json decoder first and
* then run parse_str to get some results
* if the json decoder failed.
*
* @return array
*/
public function data(): array
{
if (is_array($this->data) === true) {
return $this->data;
}
$contents = $this->contents();
$contents = $this->contents();
// return content which is already in array form
if (is_array($contents) === true) {
return $this->data = $contents;
}
// return content which is already in array form
if (is_array($contents) === true) {
return $this->data = $contents;
}
// try to convert the body from json
$json = json_decode($contents, true);
// try to convert the body from json
$json = json_decode($contents, true);
if (is_array($json) === true) {
return $this->data = $json;
}
if (is_array($json) === true) {
return $this->data = $json;
}
if (strstr($contents, '=') !== false) {
// try to parse the body as query string
parse_str($contents, $parsed);
if (strstr($contents, '=') !== false) {
// try to parse the body as query string
parse_str($contents, $parsed);
if (is_array($parsed)) {
return $this->data = $parsed;
}
}
if (is_array($parsed)) {
return $this->data = $parsed;
}
}
return $this->data = [];
}
return $this->data = [];
}
/**
* Converts the data array back
* to a http query string
*
* @return string
*/
public function toString(): string
{
return http_build_query($this->data());
}
/**
* Converts the data array back
* to a http query string
*
* @return string
*/
public function toString(): string
{
return http_build_query($this->data());
}
/**
* Magic string converter
*
* @return string
*/
public function __toString(): string
{
return $this->toString();
}
/**
* Magic string converter
*
* @return string
*/
public function __toString(): string
{
return $this->toString();
}
}

View File

@@ -18,67 +18,67 @@ namespace Kirby\Http\Request;
*/
trait Data
{
/**
* Improved `var_dump` output
*
* @return array
*/
public function __debugInfo(): array
{
return $this->toArray();
}
/**
* Improved `var_dump` output
*
* @return array
*/
public function __debugInfo(): array
{
return $this->toArray();
}
/**
* The data provider method has to be
* implemented by each class using this Trait
* and has to return an associative array
* for the get method
*
* @return array
*/
abstract public function data(): array;
/**
* The data provider method has to be
* implemented by each class using this Trait
* and has to return an associative array
* for the get method
*
* @return array
*/
abstract public function data(): array;
/**
* The get method is the heart and soul of this
* Trait. You can use it to fetch a single value
* of the data array by key or multiple values by
* passing an array of keys.
*
* @param string|array $key
* @param mixed|null $default
* @return mixed
*/
public function get($key, $default = null)
{
if (is_array($key) === true) {
$result = [];
foreach ($key as $k) {
$result[$k] = $this->get($k);
}
return $result;
}
/**
* The get method is the heart and soul of this
* Trait. You can use it to fetch a single value
* of the data array by key or multiple values by
* passing an array of keys.
*
* @param string|array $key
* @param mixed|null $default
* @return mixed
*/
public function get($key, $default = null)
{
if (is_array($key) === true) {
$result = [];
foreach ($key as $k) {
$result[$k] = $this->get($k);
}
return $result;
}
return $this->data()[$key] ?? $default;
}
return $this->data()[$key] ?? $default;
}
/**
* Returns the data array.
* This is basically an alias for Data::data()
*
* @return array
*/
public function toArray(): array
{
return $this->data();
}
/**
* Returns the data array.
* This is basically an alias for Data::data()
*
* @return array
*/
public function toArray(): array
{
return $this->data();
}
/**
* Converts the data array to json
*
* @return string
*/
public function toJson(): string
{
return json_encode($this->data());
}
/**
* Converts the data array to json
*
* @return string
*/
public function toJson(): string
{
return json_encode($this->data());
}
}

View File

@@ -17,57 +17,57 @@ namespace Kirby\Http\Request;
*/
class Files
{
use Data;
use Data;
/**
* Sanitized array of all received files
*
* @var array
*/
protected $files;
/**
* Sanitized array of all received files
*
* @var array
*/
protected $files;
/**
* Creates a new Files object
* Pass your own array to mock
* uploads.
*
* @param array|null $files
*/
public function __construct($files = null)
{
if ($files === null) {
$files = $_FILES;
}
/**
* Creates a new Files object
* Pass your own array to mock
* uploads.
*
* @param array|null $files
*/
public function __construct($files = null)
{
if ($files === null) {
$files = $_FILES;
}
$this->files = [];
$this->files = [];
foreach ($files as $key => $file) {
if (is_array($file['name'])) {
foreach ($file['name'] as $i => $name) {
$this->files[$key][] = [
'name' => $file['name'][$i] ?? null,
'type' => $file['type'][$i] ?? null,
'tmp_name' => $file['tmp_name'][$i] ?? null,
'error' => $file['error'][$i] ?? null,
'size' => $file['size'][$i] ?? null,
];
}
} else {
$this->files[$key] = $file;
}
}
}
foreach ($files as $key => $file) {
if (is_array($file['name'])) {
foreach ($file['name'] as $i => $name) {
$this->files[$key][] = [
'name' => $file['name'][$i] ?? null,
'type' => $file['type'][$i] ?? null,
'tmp_name' => $file['tmp_name'][$i] ?? null,
'error' => $file['error'][$i] ?? null,
'size' => $file['size'][$i] ?? null,
];
}
} else {
$this->files[$key] = $file;
}
}
}
/**
* The data method returns the files
* array. This is only needed to make
* the Data trait work for the Files::get($key)
* method.
*
* @return array
*/
public function data(): array
{
return $this->files;
}
/**
* The data method returns the files
* array. This is only needed to make
* the Data trait work for the Files::get($key)
* method.
*
* @return array
*/
public function data(): array
{
return $this->files;
}
}

View File

@@ -15,84 +15,84 @@ namespace Kirby\Http\Request;
*/
class Query
{
use Data;
use Data;
/**
* The Query data array
*
* @var array|null
*/
protected $data;
/**
* The Query data array
*
* @var array|null
*/
protected $data;
/**
* Creates a new Query object.
* The passed data can be an array
* or a parsable query string. If
* null is passed, the current Query
* will be taken from $_GET
*
* @param array|string|null $data
*/
public function __construct($data = null)
{
if ($data === null) {
$this->data = $_GET;
} elseif (is_array($data)) {
$this->data = $data;
} else {
parse_str($data, $parsed);
$this->data = $parsed;
}
}
/**
* Creates a new Query object.
* The passed data can be an array
* or a parsable query string. If
* null is passed, the current Query
* will be taken from $_GET
*
* @param array|string|null $data
*/
public function __construct($data = null)
{
if ($data === null) {
$this->data = $_GET;
} elseif (is_array($data)) {
$this->data = $data;
} else {
parse_str($data, $parsed);
$this->data = $parsed;
}
}
/**
* Returns the Query data as array
*
* @return array
*/
public function data(): array
{
return $this->data;
}
/**
* Returns the Query data as array
*
* @return array
*/
public function data(): array
{
return $this->data;
}
/**
* Returns `true` if the request doesn't contain query variables
*
* @return bool
*/
public function isEmpty(): bool
{
return empty($this->data) === true;
}
/**
* Returns `true` if the request doesn't contain query variables
*
* @return bool
*/
public function isEmpty(): bool
{
return empty($this->data) === true;
}
/**
* Returns `true` if the request contains query variables
*
* @return bool
*/
public function isNotEmpty(): bool
{
return empty($this->data) === false;
}
/**
* Returns `true` if the request contains query variables
*
* @return bool
*/
public function isNotEmpty(): bool
{
return empty($this->data) === false;
}
/**
* Converts the query data array
* back to a query string
*
* @return string
*/
public function toString(): string
{
return http_build_query($this->data());
}
/**
* Converts the query data array
* back to a query string
*
* @return string
*/
public function toString(): string
{
return http_build_query($this->data());
}
/**
* Magic string converter
*
* @return string
*/
public function __toString(): string
{
return $this->toString();
}
/**
* Magic string converter
*
* @return string
*/
public function __toString(): string
{
return $this->toString();
}
}