Upgrade to 3.4.3

This commit is contained in:
Bastian Allgeier
2020-09-15 10:25:09 +02:00
parent 54b9ba3047
commit d8e797dd9b
108 changed files with 1750 additions and 523 deletions

View File

@@ -36,7 +36,7 @@ class Collection extends Iterator implements Countable
/**
* Pagination object
* @var Pagination
* @var \Kirby\Toolkit\Pagination
*/
protected $pagination;
@@ -95,6 +95,7 @@ class Collection extends Iterator implements Countable
*
* @param string $key string or array
* @param mixed $value
* @return \Kirby\Toolkit\Collection
*/
public function __set(string $key, $value)
{
@@ -132,6 +133,7 @@ class Collection extends Iterator implements Countable
*
* @param mixed $key
* @param mixed $item
* @param mixed ...$args
* @return \Kirby\Toolkit\Collection
*/
public function append(...$args)
@@ -159,7 +161,7 @@ class Collection extends Iterator implements Countable
// chunk size keep keys of the elements
$chunks = array_chunk($this->data, $size, true);
// convert each chunk to a subcollection
// convert each chunk to a sub collection
$collection = [];
foreach ($chunks as $items) {
@@ -181,7 +183,7 @@ class Collection extends Iterator implements Countable
/**
* Returns a cloned instance of the collection
*
* @return self
* @return \Kirby\Toolkit\Collection
*/
public function clone()
{
@@ -191,8 +193,8 @@ class Collection extends Iterator implements Countable
/**
* Getter and setter for the data
*
* @param array $data
* @return array|Collection
* @param array|null $data
* @return array|\Kirby\Toolkit\Collection
*/
public function data(array $data = null)
{
@@ -226,7 +228,7 @@ class Collection extends Iterator implements Countable
* Adds all elements to the collection
*
* @param mixed $items
* @return self
* @return \Kirby\Toolkit\Collection
*/
public function extend($items)
{
@@ -238,8 +240,9 @@ class Collection extends Iterator implements Countable
* Filters elements by a custom
* filter function or an array of filters
*
* @param Closure $filter
* @param array|\Closure $filter
* @return self
* @throws \Exception if $filter is neither a closure nor an array
*/
public function filter($filter)
{
@@ -267,7 +270,7 @@ class Collection extends Iterator implements Countable
*
* @param string $field
* @param array ...$args
* @return self
* @return \Kirby\Toolkit\Collection
*/
public function filterBy(string $field, ...$args)
{
@@ -317,6 +320,12 @@ class Collection extends Iterator implements Countable
return $filter(clone $this, $field, $test, $split);
}
/**
* @param string $validator
* @param mixed $values
* @param mixed $test
* @return bool
*/
protected function filterMatchesAny($validator, $values, $test): bool
{
foreach ($values as $value) {
@@ -328,6 +337,12 @@ class Collection extends Iterator implements Countable
return false;
}
/**
* @param string $validator
* @param array $values
* @param mixed $test
* @return bool
*/
protected function filterMatchesAll($validator, $values, $test): bool
{
foreach ($values as $value) {
@@ -339,6 +354,12 @@ class Collection extends Iterator implements Countable
return true;
}
/**
* @param string $validator
* @param array $values
* @param mixed $test
* @return bool
*/
protected function filterMatchesNone($validator, $values, $test): bool
{
$matches = 0;
@@ -487,7 +508,7 @@ class Collection extends Iterator implements Countable
/**
* @param object $object
* @param string $attribute
* @return void
* @return mixed
*/
protected function getAttributeFromObject($object, string $attribute)
{
@@ -497,8 +518,9 @@ class Collection extends Iterator implements Countable
/**
* Groups the elements by a given callback
*
* @param Closure $callback
* @return self A new collection with an element for each group and a subcollection in each group
* @param \Closure $callback
* @return \Kirby\Toolkit\Collection A new collection with an element for each group and a sub collection in each group
* @throws \Exception
*/
public function group(Closure $callback)
{
@@ -542,7 +564,8 @@ class Collection extends Iterator implements Countable
*
* @param string $field
* @param bool $i
* @return \Kirby\Toolkit\Collection A new collection with an element for each group and a subcollection in each group
* @return \Kirby\Toolkit\Collection A new collection with an element for each group and a sub collection in each group
* @throws \Exception
*/
public function groupBy($field, bool $i = true)
{
@@ -728,7 +751,7 @@ class Collection extends Iterator implements Countable
* a new array
*
* @param string $field
* @param string $split
* @param string|null $split
* @param bool $unique
* @return array
*/
@@ -758,7 +781,8 @@ class Collection extends Iterator implements Countable
*
* @param mixed $key
* @param mixed $item
* @return self
* @param mixed ...$args
* @return \Kirby\Toolkit\Collection
*/
public function prepend(...$args)
{
@@ -780,7 +804,7 @@ class Collection extends Iterator implements Countable
* Any part of the query is optional.
*
* @param array $arguments
* @return self
* @return \Kirby\Toolkit\Collection
*/
public function query(array $arguments = [])
{
@@ -810,6 +834,11 @@ class Collection extends Iterator implements Countable
if (is_array($arguments['sortBy'])) {
$sort = explode(' ', implode(' ', $arguments['sortBy']));
} else {
// if there are commas in the sortBy argument, removes it
if (Str::contains($arguments['sortBy'], ',') === true) {
$arguments['sortBy'] = Str::replace($arguments['sortBy'], ',', '');
}
$sort = explode(' ', $arguments['sortBy']);
}
$result = $result->sortBy(...$sort);
@@ -826,6 +855,7 @@ class Collection extends Iterator implements Countable
* Removes an element from the array by key
*
* @param mixed $key the name of the key
* @return \Kirby\Toolkit\Collection
*/
public function remove($key)
{
@@ -838,7 +868,7 @@ class Collection extends Iterator implements Countable
*
* @param mixed $key string or array
* @param mixed $value
* @return self
* @return \Kirby\Toolkit\Collection
*/
public function set($key, $value = null)
{
@@ -877,7 +907,7 @@ class Collection extends Iterator implements Countable
* Returns a slice of the object
*
* @param int $offset The optional index to start the slice from
* @param int $limit The optional number of elements to return
* @param int|null $limit The optional number of elements to return
* @return \Kirby\Toolkit\Collection
*/
public function slice(int $offset = 0, int $limit = null)
@@ -899,6 +929,11 @@ class Collection extends Iterator implements Countable
*/
public static function sortArgs(string $sortBy): array
{
// if there are commas in the sortBy argument, removes it
if (Str::contains($sortBy, ',') === true) {
$sortBy = Str::replace($sortBy, ',', '');
}
$sortArgs = Str::split($sortBy, ' ');
// fill in PHP constants
@@ -917,7 +952,7 @@ class Collection extends Iterator implements Countable
* @param string|callable $field Field name or value callback to sort by
* @param string $direction asc or desc
* @param int $method The sort flag, SORT_REGULAR, SORT_NUMERIC etc.
* @return Collection
* @return \Kirby\Toolkit\Collection
*/
public function sortBy()
{
@@ -1030,7 +1065,7 @@ class Collection extends Iterator implements Countable
/**
* Converts the object into an array
*
* @param Closure $map
* @param \Closure|null $map
* @return array
*/
public function toArray(Closure $map = null): array
@@ -1053,7 +1088,7 @@ class Collection extends Iterator implements Countable
}
/**
* Convertes the object to a string
* Converts the object to a string
*
* @return string
*/
@@ -1078,11 +1113,11 @@ class Collection extends Iterator implements Countable
* is true. If the first parameter is false, the Closure will not be executed.
* You may pass another Closure as the third parameter to the when method.
* This Closure will execute if the first parameter evaluates as false
* @since 3.3.0
*
* @since 3.3.0
* @param mixed $condition
* @param Closure $callback
* @param Closure $fallback
* @param \Closure $callback
* @param \Closure|null $fallback
* @return mixed
*/
public function when($condition, Closure $callback, Closure $fallback = null)
@@ -1112,6 +1147,12 @@ class Collection extends Iterator implements Countable
/**
* Equals Filter
*
* @param \Kirby\Toolkit\Collection $collection
* @param mixed $field
* @param mixed $test
* @param bool $split
* @return mixed
*/
Collection::$filters['=='] = function ($collection, $field, $test, $split = false) {
foreach ($collection->data as $key => $item) {
@@ -1131,6 +1172,12 @@ Collection::$filters['=='] = function ($collection, $field, $test, $split = fals
/**
* Not Equals Filter
*
* @param \Kirby\Toolkit\Collection $collection
* @param mixed $field
* @param mixed $test
* @param bool $split
* @return mixed
*/
Collection::$filters['!='] = function ($collection, $field, $test, $split = false) {
foreach ($collection->data as $key => $item) {

View File

@@ -128,6 +128,7 @@ class Pagination
*
* @deprecated 3.3.0 Setter is no longer supported, use $pagination->clone()
* @return int
* @codeCoverageIgnore
*/
public function page(int $page = null): int
{
@@ -143,6 +144,7 @@ class Pagination
*
* @deprecated 3.3.0 Setter is no longer supported, use $pagination->clone()
* @return int
* @codeCoverageIgnore
*/
public function total(int $total = null): int
{
@@ -158,6 +160,7 @@ class Pagination
*
* @deprecated 3.3.0 Setter is no longer supported, use $pagination->clone()
* @return int
* @codeCoverageIgnore
*/
public function limit(int $limit = null): int
{

View File

@@ -179,7 +179,7 @@ class Str
$position = static::position($string, $needle, $caseInsensitive);
if ($position === false) {
return false;
return '';
} else {
return static::substr($string, $position + static::length($needle));
}
@@ -221,7 +221,7 @@ class Str
$position = static::position($string, $needle, $caseInsensitive);
if ($position === false) {
return false;
return '';
} else {
return static::substr($string, 0, $position);
}
@@ -396,7 +396,7 @@ class Str
$position = static::position($string, $needle, $caseInsensitive);
if ($position === false) {
return false;
return '';
} else {
return static::substr($string, $position);
}
@@ -748,8 +748,12 @@ class Str
* string is too long. Ellipsis is the default.
* @return string The shortened string
*/
public static function short(string $string = null, int $length = 0, string $appendix = '…'): ?string
public static function short(string $string = null, int $length = 0, string $appendix = '…'): string
{
if ($string === null) {
return '';
}
if ($length === 0) {
return $string;
}
@@ -1041,7 +1045,7 @@ class Str
$position = static::position($string, $needle, $caseInsensitive);
if ($position === false) {
return false;
return '';
} else {
return static::substr($string, 0, $position + static::length($needle));
}

View File

@@ -153,7 +153,10 @@ class V
$fieldValue = $input[$fieldName] ?? null;
// first check for required fields
if (($fieldRules['required'] ?? false) === true && $fieldValue === null) {
if (
($fieldRules['required'] ?? false) === true &&
$fieldValue === null
) {
throw new Exception(sprintf('The "%s" field is missing', $fieldName));
}
@@ -166,12 +169,10 @@ class V
}
try {
V::value($fieldValue, $fieldRules);
static::value($fieldValue, $fieldRules);
} catch (Exception $e) {
throw new Exception(sprintf($e->getMessage() . ' for field "%s"', $fieldName));
}
static::value($fieldValue, $fieldRules);
}
return true;
@@ -213,15 +214,15 @@ V::$validators = [
/**
* Valid: `a-z | A-Z`
*/
'alpha' => function ($value): bool {
return V::match($value, '/^([a-z])+$/i') === true;
'alpha' => function ($value, bool $unicode = false): bool {
return V::match($value, ($unicode === true ? '/^([\pL])+$/u' : '/^([a-z])+$/i')) === true;
},
/**
* Valid: `a-z | A-Z | 0-9`
*/
'alphanum' => function ($value): bool {
return V::match($value, '/^[a-z0-9]+$/i') === true;
'alphanum' => function ($value, bool $unicode = false): bool {
return V::match($value, ($unicode === true ? '/^[\pL\pN]+$/u' : '/^([a-z0-9])+$/i')) === true;
},
/**