Skip to content
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

[11.x] Collection::wrap #53891

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions src/Illuminate/Concurrency/SyncDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Closure;
use Illuminate\Contracts\Concurrency\Driver;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Defer\DeferredCallback;

Expand All @@ -17,7 +16,7 @@ class SyncDriver implements Driver
*/
public function run(Closure|array $tasks): array
{
return (new Collection(Arr::wrap($tasks)))->map(
return Collection::wrap($tasks)->map(
fn ($task) => $task()
)->all();
}
Expand All @@ -27,6 +26,6 @@ public function run(Closure|array $tasks): array
*/
public function defer(Closure|array $tasks): DeferredCallback
{
return defer(fn () => (new Collection(Arr::wrap($tasks)))->each(fn ($task) => $task()));
return defer(fn () => Collection::wrap($tasks)->each(fn ($task) => $task()));
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Concerns/InteractsWithSignals.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function trap($signals, $callback)
$this->getApplication()->getSignalRegistry(),
);

(new Collection(Arr::wrap(value($signals))))
Collection::wrap(value($signals))
->each(fn ($signal) => $this->signals->register($signal, $callback));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function ofMany($column = 'id', $aggregate = 'MAX', $relation = null)
*/
public function latestOfMany($column = 'id', $relation = null)
{
return $this->ofMany((new Collection(Arr::wrap($column)))->mapWithKeys(function ($column) {
return $this->ofMany(Collection::wrap($column)->mapWithKeys(function ($column) {
return [$column => 'MAX'];
})->all(), 'MAX', $relation);
}
Expand All @@ -165,7 +165,7 @@ public function latestOfMany($column = 'id', $relation = null)
*/
public function oldestOfMany($column = 'id', $relation = null)
{
return $this->ofMany((new Collection(Arr::wrap($column)))->mapWithKeys(function ($column) {
return $this->ofMany(Collection::wrap($column)->mapWithKeys(function ($column) {
return [$column => 'MIN'];
})->all(), 'MIN', $relation);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Illuminate/Queue/Middleware/RateLimited.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Cache\RateLimiter;
use Illuminate\Cache\RateLimiting\Unlimited;
use Illuminate\Container\Container;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

use function Illuminate\Support\enum_value;
Expand Down Expand Up @@ -68,7 +67,7 @@ public function handle($job, $next)
return $this->handleJob(
$job,
$next,
(new Collection(Arr::wrap($limiterResponse)))->map(function ($limit) {
Collection::wrap($limiterResponse)->map(function ($limit) {
return (object) [
'key' => md5($this->limiterName.$limit->key),
'maxAttempts' => $limit->maxAttempts,
Expand Down
3 changes: 1 addition & 2 deletions src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
use Illuminate\Queue\Events\JobQueued;
use Illuminate\Queue\Events\JobQueueing;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\InteractsWithTime;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -215,7 +214,7 @@ public function getJobBackoff($job)
return;
}

return (new Collection(Arr::wrap($backoff)))
return Collection::wrap($backoff)
->map(fn ($backoff) => $backoff instanceof DateTimeInterface ? $this->secondsUntil($backoff) : $backoff)
->implode(',');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Illuminate\Routing;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

use function Illuminate\Support\enum_value;
Expand Down Expand Up @@ -90,7 +89,7 @@ public function whereIn($parameters, array $values)
*/
protected function assignExpressionToParameters($parameters, $expression)
{
return $this->where((new Collection(Arr::wrap($parameters)))
return $this->where(Collection::wrap($parameters)
->mapWithKeys(fn ($parameter) => [$parameter => $expression])
->all());
}
Expand Down
3 changes: 1 addition & 2 deletions src/Illuminate/Routing/Middleware/ThrottleRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\Exceptions\ThrottleRequestsException;
use Illuminate\Routing\Exceptions\MissingRateLimiterException;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\InteractsWithTime;
use RuntimeException;
Expand Down Expand Up @@ -128,7 +127,7 @@ protected function handleRequestUsingNamedLimiter($request, Closure $next, $limi
return $this->handleRequest(
$request,
$next,
(new Collection(Arr::wrap($limiterResponse)))->map(function ($limit) use ($limiterName) {
Collection::wrap($limiterResponse)->map(function ($limit) use ($limiterName) {
return (object) [
'key' => self::$shouldHashKeys ? md5($limiterName.$limit->key) : $limiterName.':'.$limit->key,
'maxAttempts' => $limit->maxAttempts,
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public function route($name, $parameters = [], $absolute = true)
*/
public function toRoute($route, $parameters, $absolute)
{
$parameters = (new Collection(Arr::wrap($parameters)))->map(function ($value, $key) use ($route) {
$parameters = Collection::wrap($parameters)->map(function ($value, $key) use ($route) {
return $value instanceof UrlRoutable && $route->bindingFieldFor($key)
? $value->{$route->bindingFieldFor($key)}
: $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Benchmark
*/
public static function measure(Closure|array $benchmarkables, int $iterations = 1): array|float
{
return (new Collection(Arr::wrap($benchmarkables)))->map(function ($callback) use ($iterations) {
return Collection::wrap($benchmarkables)->map(function ($callback) use ($iterations) {
return (new Collection(range(1, $iterations)))->map(function () use ($callback) {
gc_collect_cycles();

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Rules/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected function buildMimetypes()
*/
protected function fail($messages)
{
$messages = (new Collection(Arr::wrap($messages)))
$messages = Collection::wrap($messages)
->map(fn ($message) => $this->validator->getTranslator()->get($message))
->all();

Expand Down
Loading