Upgrade to 3.8.0

This commit is contained in:
Bastian Allgeier
2022-10-06 10:11:54 +02:00
parent a9ed4e45ca
commit 7d168aae58
332 changed files with 26337 additions and 21977 deletions

View File

@@ -262,7 +262,7 @@ class Database
*
* @return string|null
*/
public function prefix(): ?string
public function prefix(): string|null
{
return $this->prefix;
}
@@ -303,7 +303,7 @@ class Database
*
* @return int|null
*/
public function affected(): ?int
public function affected(): int|null
{
return $this->affected;
}
@@ -313,7 +313,7 @@ class Database
*
* @return int|null
*/
public function lastId(): ?int
public function lastId(): int|null
{
return $this->lastId;
}
@@ -323,7 +323,7 @@ class Database
*
* @return string|null
*/
public function lastQuery(): ?string
public function lastQuery(): string|null
{
return $this->lastQuery;
}
@@ -353,7 +353,7 @@ class Database
*
* @return string|null
*/
public function name(): ?string
public function name(): string|null
{
return $this->database;
}
@@ -427,7 +427,10 @@ class Database
}
// define the default flag for the fetch method
if ($options['fetch'] instanceof Closure || $options['fetch'] === 'array') {
if (
$options['fetch'] instanceof Closure ||
$options['fetch'] === 'array'
) {
$flags = PDO::FETCH_ASSOC;
} else {
$flags = PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE;

View File

@@ -37,7 +37,7 @@ class Db
* don't pass any argument to get the current connection
* @return \Kirby\Database\Database
*/
public static function connect(?array $params = null)
public static function connect(array|null $params = null)
{
if ($params === null && static::$connection !== null) {
return static::$connection;

View File

@@ -404,18 +404,7 @@ class Query
*/
public function orWhere(...$args)
{
$mode = A::last($args);
// if there's a where clause mode attribute attached…
if (in_array($mode, ['AND', 'OR'], true) === true) {
// remove that from the list of arguments
array_pop($args);
}
// make sure to always attach the OR mode indicator
$args[] = 'OR';
$this->where(...$args);
$this->where = $this->filterQuery($args, $this->where, 'OR');
return $this;
}
@@ -428,18 +417,7 @@ class Query
*/
public function andWhere(...$args)
{
$mode = A::last($args);
// if there's a where clause mode attribute attached…
if (in_array($mode, ['AND', 'OR'], true) === true) {
// remove that from the list of arguments
array_pop($args);
}
// make sure to always attach the AND mode indicator
$args[] = 'AND';
$this->where(...$args);
$this->where = $this->filterQuery($args, $this->where, 'AND');
return $this;
}
@@ -522,41 +500,38 @@ class Query
{
$sql = $this->database->sql();
switch ($type) {
case 'select':
return $sql->select([
'table' => $this->table,
'columns' => $this->select,
'join' => $this->join,
'distinct' => $this->distinct,
'where' => $this->where,
'group' => $this->group,
'having' => $this->having,
'order' => $this->order,
'offset' => $this->offset,
'limit' => $this->limit,
'bindings' => $this->bindings
]);
case 'update':
return $sql->update([
'table' => $this->table,
'where' => $this->where,
'values' => $this->values,
'bindings' => $this->bindings
]);
case 'insert':
return $sql->insert([
'table' => $this->table,
'values' => $this->values,
'bindings' => $this->bindings
]);
case 'delete':
return $sql->delete([
'table' => $this->table,
'where' => $this->where,
'bindings' => $this->bindings
]);
}
return match ($type) {
'select' => $sql->select([
'table' => $this->table,
'columns' => $this->select,
'join' => $this->join,
'distinct' => $this->distinct,
'where' => $this->where,
'group' => $this->group,
'having' => $this->having,
'order' => $this->order,
'offset' => $this->offset,
'limit' => $this->limit,
'bindings' => $this->bindings
]),
'update' => $sql->update([
'table' => $this->table,
'where' => $this->where,
'values' => $this->values,
'bindings' => $this->bindings
]),
'insert' => $sql->insert([
'table' => $this->table,
'values' => $this->values,
'bindings' => $this->bindings
]),
'delete' => $sql->delete([
'table' => $this->table,
'where' => $this->where,
'bindings' => $this->bindings
]),
default => null
};
}
/**
@@ -935,19 +910,10 @@ class Query
* @param mixed $current Current value (like $this->where)
* @return string
*/
protected function filterQuery(array $args, $current)
protected function filterQuery(array $args, $current, string $mode = 'AND')
{
$mode = A::last($args);
$result = '';
// if there's a where clause mode attribute attached…
if (in_array($mode, ['AND', 'OR'], true) === true) {
// remove that from the list of arguments
array_pop($args);
} else {
$mode = 'AND';
}
switch (count($args)) {
case 1:

View File

@@ -118,7 +118,7 @@ abstract class Sql
* @param bool $enforceQualified If true, a qualified identifier is returned in all cases
* @return string|null Identifier or null if the table or column is invalid
*/
public function columnName(string $table, string $column, bool $enforceQualified = false): ?string
public function columnName(string $table, string $column, bool $enforceQualified = false): string|null
{
// ensure we have clean $table and $column values without qualified identifiers
list($table, $column) = $this->splitIdentifier($table, $column);
@@ -702,19 +702,19 @@ abstract class Sql
// split by dot, but only outside of quotes
$parts = preg_split('/(?:`[^`]*`|"[^"]*")(*SKIP)(*F)|\./', $identifier);
switch (count($parts)) {
case 1:
// non-qualified identifier
return [$table, $this->unquoteIdentifier($parts[0])];
return match (count($parts)) {
// non-qualified identifier
1 => [$table, $this->unquoteIdentifier($parts[0])],
case 2:
// qualified identifier
return [$this->unquoteIdentifier($parts[0]), $this->unquoteIdentifier($parts[1])];
// qualified identifier
2 => [
$this->unquoteIdentifier($parts[0]),
$this->unquoteIdentifier($parts[1])
],
default:
// every other number is an error
throw new InvalidArgumentException('Invalid identifier ' . $identifier);
}
// every other number is an error
default => throw new InvalidArgumentException('Invalid identifier ' . $identifier)
};
}
/**