Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[10.x] Add Arr::from() #49202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Undeprecate EnumeratesValues::getArrayableItems
  • Loading branch information
Sergey Danilchenko committed Nov 30, 2023
commit 50875be44be148a8bce55247fb65bce993f43e7a
44 changes: 22 additions & 22 deletions 44 src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
*/
public function __construct($items = [])
{
$this->items = Arr::from($items);
$this->items = $this->getArrayableItems($items);
}

/**
Expand Down Expand Up @@ -227,7 +227,7 @@ public function doesntContain($key, $operator = null, $value = null)
public function crossJoin(...$lists)
{
return new static(Arr::crossJoin(
$this->items, ...array_map(Arr::from(...), $lists)
$this->items, ...array_map([$this, 'getArrayableItems'], $lists)
));
}

Expand All @@ -239,7 +239,7 @@ public function crossJoin(...$lists)
*/
public function diff($items)
{
return new static(array_diff($this->items, Arr::from($items)));
return new static(array_diff($this->items, $this->getArrayableItems($items)));
}

/**
Expand All @@ -251,7 +251,7 @@ public function diff($items)
*/
public function diffUsing($items, callable $callback)
{
return new static(array_udiff($this->items, Arr::from($items), $callback));
return new static(array_udiff($this->items, $this->getArrayableItems($items), $callback));
}

/**
Expand All @@ -262,7 +262,7 @@ public function diffUsing($items, callable $callback)
*/
public function diffAssoc($items)
{
return new static(array_diff_assoc($this->items, Arr::from($items)));
return new static(array_diff_assoc($this->items, $this->getArrayableItems($items)));
}

/**
Expand All @@ -274,7 +274,7 @@ public function diffAssoc($items)
*/
public function diffAssocUsing($items, callable $callback)
{
return new static(array_diff_uassoc($this->items, Arr::from($items), $callback));
return new static(array_diff_uassoc($this->items, $this->getArrayableItems($items), $callback));
}

/**
Expand All @@ -285,7 +285,7 @@ public function diffAssocUsing($items, callable $callback)
*/
public function diffKeys($items)
{
return new static(array_diff_key($this->items, Arr::from($items)));
return new static(array_diff_key($this->items, $this->getArrayableItems($items)));
}

/**
Expand All @@ -297,7 +297,7 @@ public function diffKeys($items)
*/
public function diffKeysUsing($items, callable $callback)
{
return new static(array_diff_ukey($this->items, Arr::from($items), $callback));
return new static(array_diff_ukey($this->items, $this->getArrayableItems($items), $callback));
}

/**
Expand Down Expand Up @@ -434,7 +434,7 @@ public function flip()
*/
public function forget($keys)
{
foreach (Arr::from($keys) as $key) {
foreach ($this->getArrayableItems($keys) as $key) {
$this->offsetUnset($key);
}

Expand Down Expand Up @@ -627,7 +627,7 @@ public function implode($value, $glue = null)
*/
public function intersect($items)
{
return new static(array_intersect($this->items, Arr::from($items)));
return new static(array_intersect($this->items, $this->getArrayableItems($items)));
}

/**
Expand All @@ -639,7 +639,7 @@ public function intersect($items)
*/
public function intersectUsing($items, callable $callback)
{
return new static(array_uintersect($this->items, Arr::from($items), $callback));
return new static(array_uintersect($this->items, $this->getArrayableItems($items), $callback));
}

/**
Expand All @@ -650,7 +650,7 @@ public function intersectUsing($items, callable $callback)
*/
public function intersectAssoc($items)
{
return new static(array_intersect_assoc($this->items, Arr::from($items)));
return new static(array_intersect_assoc($this->items, $this->getArrayableItems($items)));
}

/**
Expand All @@ -662,7 +662,7 @@ public function intersectAssoc($items)
*/
public function intersectAssocUsing($items, callable $callback)
{
return new static(array_intersect_uassoc($this->items, Arr::from($items), $callback));
return new static(array_intersect_uassoc($this->items, $this->getArrayableItems($items), $callback));
}

/**
Expand All @@ -674,7 +674,7 @@ public function intersectAssocUsing($items, callable $callback)
public function intersectByKeys($items)
{
return new static(array_intersect_key(
$this->items, Arr::from($items)
$this->items, $this->getArrayableItems($items)
));
}

Expand Down Expand Up @@ -833,7 +833,7 @@ public function mapWithKeys(callable $callback)
*/
public function merge($items)
{
return new static(array_merge($this->items, Arr::from($items)));
return new static(array_merge($this->items, $this->getArrayableItems($items)));
}

/**
Expand All @@ -846,7 +846,7 @@ public function merge($items)
*/
public function mergeRecursive($items)
{
return new static(array_merge_recursive($this->items, Arr::from($items)));
return new static(array_merge_recursive($this->items, $this->getArrayableItems($items)));
}

/**
Expand All @@ -859,7 +859,7 @@ public function mergeRecursive($items)
*/
public function combine($values)
{
return new static(array_combine($this->all(), Arr::from($values)));
return new static(array_combine($this->all(), $this->getArrayableItems($values)));
}

/**
Expand All @@ -870,7 +870,7 @@ public function combine($values)
*/
public function union($items)
{
return new static($this->items + Arr::from($items));
return new static($this->items + $this->getArrayableItems($items));
}

/**
Expand Down Expand Up @@ -1049,7 +1049,7 @@ public function random($number = null, $preserveKeys = false)
*/
public function replace($items)
{
return new static(array_replace($this->items, Arr::from($items)));
return new static(array_replace($this->items, $this->getArrayableItems($items)));
}

/**
Expand All @@ -1060,7 +1060,7 @@ public function replace($items)
*/
public function replaceRecursive($items)
{
return new static(array_replace_recursive($this->items, Arr::from($items)));
return new static(array_replace_recursive($this->items, $this->getArrayableItems($items)));
}

/**
Expand Down Expand Up @@ -1513,7 +1513,7 @@ public function splice($offset, $length = null, $replacement = [])
return new static(array_splice($this->items, $offset));
}

return new static(array_splice($this->items, $offset, $length, Arr::from($replacement)));
return new static(array_splice($this->items, $offset, $length, $this->getArrayableItems($replacement)));
}

/**
Expand Down Expand Up @@ -1635,7 +1635,7 @@ public function values()
*/
public function zip($items)
{
$arrayableItems = array_map(fn ($items) => Arr::from($items), func_get_args());
$arrayableItems = array_map(fn ($items) => $this->getArrayableItems($items), func_get_args());

$params = array_merge([fn () => new static(func_get_args()), $this->items], $arrayableItems);

Expand Down
4 changes: 2 additions & 2 deletions 4 src/Illuminate/Collections/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct($source = null)
'Generators should not be passed directly to LazyCollection. Instead, pass a generator function.'
);
} else {
$this->source = Arr::from($source);
$this->source = $this->getArrayableItems($source);
}
}

Expand Down Expand Up @@ -991,7 +991,7 @@ public function random($number = null)
public function replace($items)
{
return new static(function () use ($items) {
$items = Arr::from($items);
$items = $this->getArrayableItems($items);

foreach ($this as $key => $value) {
if (array_key_exists($key, $items)) {
Expand Down
6 changes: 2 additions & 4 deletions 6 src/Illuminate/Collections/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ public function whereStrict($key, $value)
*/
public function whereIn($key, $values, $strict = false)
{
$values = Arr::from($values);
$values = $this->getArrayableItems($values);

return $this->filter(fn ($item) => in_array(data_get($item, $key), $values, $strict));
}
Expand Down Expand Up @@ -687,7 +687,7 @@ public function whereNotBetween($key, $values)
*/
public function whereNotIn($key, $values, $strict = false)
{
$values = Arr::from($values);
$values = $this->getArrayableItems($values);

return $this->reject(fn ($item) => in_array(data_get($item, $key), $values, $strict));
}
Expand Down Expand Up @@ -1013,8 +1013,6 @@ public function __get($key)
/**
* Results array of items from Collection or Arrayable.
*
* @deprecated Will be removed in a future Laravel version.
*
* @param mixed $items
* @return array<TKey, TValue>
*/
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.