Upgrade to 4.0.0

This commit is contained in:
Bastian Allgeier
2023-11-28 09:33:56 +01:00
parent f96b96af76
commit 3b0b6546ca
480 changed files with 21371 additions and 13327 deletions

View File

@@ -30,6 +30,9 @@ class Collection extends Iterator implements Countable
* Whether the collection keys should be
* treated as case-sensitive
*
* @todo 5.0 Check if case-sensitive can become the
* default mode, see https://github.com/getkirby/kirby/pull/5635
*
* @var bool
*/
protected $caseSensitive = false;
@@ -67,8 +70,7 @@ class Collection extends Iterator implements Countable
/**
* Improve var_dump() output
*
* @return array
* @codeCoverageIgnore
*/
public function __debugInfo(): array
{
@@ -521,21 +523,24 @@ class Collection extends Iterator implements Countable
* Groups the elements by a given field or callback function
*
* @param string|Closure $field
* @param bool $i
* @return \Kirby\Toolkit\Collection A new collection with an element for
* each group and a subcollection in
* each group
* @throws \Exception if $field is not a string nor a callback function
*/
public function group($field, bool $i = true)
public function group($field, bool $caseInsensitive = true)
{
// group by field name
if (is_string($field) === true) {
return $this->group(function ($item) use ($field, $i) {
return $this->group(function ($item) use ($field, $caseInsensitive) {
$value = $this->getAttribute($item, $field);
// ignore upper/lowercase for group names
return $i === true ? Str::lower($value) : (string)$value;
if ($caseInsensitive === true) {
return Str::lower($value);
}
return (string)$value;
});
}
@@ -740,14 +745,17 @@ class Collection extends Iterator implements Countable
* Add pagination
*
* @param array ...$arguments
* @return static a sliced set of data
* @return $this|static a sliced set of data
*/
public function paginate(...$arguments)
{
$this->pagination = Pagination::for($this, ...$arguments);
// slice and clone the collection according to the pagination
return $this->slice($this->pagination->offset(), $this->pagination->limit());
return $this->slice(
$this->pagination->offset(),
$this->pagination->limit()
);
}
/**