Upgrade to 3.4.3
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user