Skip to content

Commit 941c62c

Browse files
committed
Merge branch '12.x' into json-api-resource
2 parents 69086d4 + 1e78dfb commit 941c62c

File tree

26 files changed

+1453
-66
lines changed

26 files changed

+1453
-66
lines changed

src/Illuminate/Broadcasting/UniqueBroadcastEvent.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class UniqueBroadcastEvent extends BroadcastEvent implements ShouldBeUnique
2929
*/
3030
public function __construct($event)
3131
{
32-
$this->uniqueId = get_class($event);
33-
3432
if (method_exists($event, 'uniqueId')) {
3533
$this->uniqueId .= $event->uniqueId();
3634
} elseif (property_exists($event, 'uniqueId')) {

src/Illuminate/Bus/UniqueLock.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public static function getKey($job)
6969
? $job->uniqueId()
7070
: ($job->uniqueId ?? '');
7171

72-
return 'laravel_unique_job:'.get_class($job).':'.$uniqueId;
72+
$jobName = method_exists($job, 'displayName')
73+
? $job->displayName()
74+
: get_class($job);
75+
76+
return 'laravel_unique_job:'.$jobName.':'.$uniqueId;
7377
}
7478
}

src/Illuminate/Cache/Console/stubs/cache.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ return new class extends Migration
1414
Schema::create('cache', function (Blueprint $table) {
1515
$table->string('key')->primary();
1616
$table->mediumText('value');
17-
$table->integer('expiration');
17+
$table->integer('expiration')->index();
1818
});
1919

2020
Schema::create('cache_locks', function (Blueprint $table) {
2121
$table->string('key')->primary();
2222
$table->string('owner');
23-
$table->integer('expiration');
23+
$table->integer('expiration')->index();
2424
});
2525
}
2626

src/Illuminate/Collections/Arr.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public static function exists($array, $key)
242242
}
243243

244244
/**
245-
* Return the first element in an array passing a given truth test.
245+
* Return the first element in an iterable passing a given truth test.
246246
*
247247
* @template TKey
248248
* @template TValue
@@ -271,6 +271,8 @@ public static function first($array, ?callable $callback = null, $default = null
271271
return value($default);
272272
}
273273

274+
$array = static::from($array);
275+
274276
$key = array_find_key($array, $callback);
275277

276278
return $key !== null ? $array[$key] : value($default);

src/Illuminate/Container/Container.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
use Illuminate\Contracts\Container\Container as ContainerContract;
1414
use Illuminate\Contracts\Container\ContextualAttribute;
1515
use Illuminate\Contracts\Container\SelfBuilding;
16-
use Illuminate\Support\Collection;
16+
use Illuminate\Support\Traits\ReflectsClosures;
1717
use LogicException;
1818
use ReflectionAttribute;
1919
use ReflectionClass;
2020
use ReflectionException;
2121
use ReflectionFunction;
22-
use ReflectionIntersectionType;
2322
use ReflectionParameter;
24-
use ReflectionUnionType;
2523
use TypeError;
2624

2725
class Container implements ArrayAccess, ContainerContract
2826
{
27+
use ReflectsClosures;
28+
2929
/**
3030
* The current globally available container (if any).
3131
*
@@ -568,35 +568,6 @@ protected function bindBasedOnClosureReturnTypes($abstract, $concrete = null, $s
568568
}
569569
}
570570

571-
/**
572-
* Get the class names / types of the return type of the given Closure.
573-
*
574-
* @param \Closure $closure
575-
* @return list<class-string>
576-
*
577-
* @throws \ReflectionException
578-
*/
579-
protected function closureReturnTypes(Closure $closure)
580-
{
581-
$reflection = new ReflectionFunction($closure);
582-
583-
if ($reflection->getReturnType() === null ||
584-
$reflection->getReturnType() instanceof ReflectionIntersectionType) {
585-
return [];
586-
}
587-
588-
$types = $reflection->getReturnType() instanceof ReflectionUnionType
589-
? $reflection->getReturnType()->getTypes()
590-
: [$reflection->getReturnType()];
591-
592-
return (new Collection($types))
593-
->reject(fn ($type) => $type->isBuiltin())
594-
->reject(fn ($type) => in_array($type->getName(), ['static', 'self']))
595-
->map(fn ($type) => $type->getName())
596-
->values()
597-
->all();
598-
}
599-
600571
/**
601572
* "Extend" an abstract type in the container.
602573
*

src/Illuminate/Database/Connection.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,16 @@ public function pretend(Closure $callback)
646646
return $this->withFreshQueryLog(function () use ($callback) {
647647
$this->pretending = true;
648648

649-
// Basically to make the database connection "pretend", we will just return
650-
// the default values for all the query methods, then we will return an
651-
// array of queries that were "executed" within the Closure callback.
652-
$callback($this);
653-
654-
$this->pretending = false;
655-
656-
return $this->queryLog;
649+
try {
650+
// Basically to make the database connection "pretend", we will just return
651+
// the default values for all the query methods, then we will return an
652+
// array of queries that were "executed" within the Closure callback.
653+
$callback($this);
654+
655+
return $this->queryLog;
656+
} finally {
657+
$this->pretending = false;
658+
}
657659
});
658660
}
659661

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,11 +2447,11 @@ public function offsetExists($offset): bool
24472447

24482448
static::$modelsShouldPreventAccessingMissingAttributes = false;
24492449

2450-
$result = ! is_null($this->getAttribute($offset));
2451-
2452-
static::$modelsShouldPreventAccessingMissingAttributes = $shouldPrevent;
2453-
2454-
return $result;
2450+
try {
2451+
return ! is_null($this->getAttribute($offset));
2452+
} finally {
2453+
static::$modelsShouldPreventAccessingMissingAttributes = $shouldPrevent;
2454+
}
24552455
}
24562456

24572457
/**
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace Illuminate\Foundation\Console;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Collection;
7+
use Illuminate\Support\ServiceProvider;
8+
use Symfony\Component\Console\Attribute\AsCommand;
9+
use Symfony\Component\Console\Input\InputOption;
10+
11+
#[AsCommand(name: 'reload')]
12+
class ReloadCommand extends Command
13+
{
14+
/**
15+
* The console command name.
16+
*
17+
* @var string
18+
*/
19+
protected $name = 'reload';
20+
21+
/**
22+
* The console command description.
23+
*
24+
* @var string
25+
*/
26+
protected $description = 'Reload running services';
27+
28+
/**
29+
* Execute the console command.
30+
*
31+
* @return void
32+
*/
33+
public function handle()
34+
{
35+
$this->components->info('Reloading services.');
36+
37+
$exceptions = Collection::wrap(explode(',', $this->option('except') ?? ''))
38+
->map(fn ($except) => trim($except))
39+
->filter()
40+
->unique()
41+
->flip();
42+
43+
$tasks = Collection::wrap($this->getReloadTasks())
44+
->reject(fn ($command, $key) => $exceptions->hasAny([$command, $key]))
45+
->toArray();
46+
47+
foreach ($tasks as $description => $command) {
48+
$this->components->task($description, fn () => $this->callSilently($command) == 0);
49+
}
50+
51+
$this->newLine();
52+
}
53+
54+
/**
55+
* Get the commands that should be run to clear the "optimization" files.
56+
*
57+
* @return array
58+
*/
59+
public function getReloadTasks()
60+
{
61+
return [
62+
'queue' => 'queue:restart',
63+
...ServiceProvider::$reloadCommands,
64+
];
65+
}
66+
67+
/**
68+
* Get the console command arguments.
69+
*
70+
* @return array
71+
*/
72+
protected function getOptions()
73+
{
74+
return [
75+
['except', 'e', InputOption::VALUE_OPTIONAL, 'The commands to skip'],
76+
];
77+
}
78+
}

src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
use Illuminate\Foundation\Console\PackageDiscoverCommand;
7171
use Illuminate\Foundation\Console\PolicyMakeCommand;
7272
use Illuminate\Foundation\Console\ProviderMakeCommand;
73+
use Illuminate\Foundation\Console\ReloadCommand;
7374
use Illuminate\Foundation\Console\RequestMakeCommand;
7475
use Illuminate\Foundation\Console\ResourceMakeCommand;
7576
use Illuminate\Foundation\Console\RouteCacheCommand;
@@ -160,6 +161,7 @@ class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvid
160161
'QueueRetry' => QueueRetryCommand::class,
161162
'QueueRetryBatch' => QueueRetryBatchCommand::class,
162163
'QueueWork' => QueueWorkCommand::class,
164+
'Reload' => ReloadCommand::class,
163165
'RouteCache' => RouteCacheCommand::class,
164166
'RouteClear' => RouteClearCommand::class,
165167
'RouteList' => RouteListCommand::class,
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
namespace Illuminate\Http\Client;
4+
5+
use GuzzleHttp\Promise\PromiseInterface;
6+
use Illuminate\Support\Traits\ForwardsCalls;
7+
8+
/**
9+
* A decorated Promise which allows for chaining callbacks.
10+
*/
11+
class FluentPromise implements PromiseInterface
12+
{
13+
use ForwardsCalls;
14+
15+
/**
16+
* Create a new fluent promise instance.
17+
*
18+
* @param \GuzzleHttp\Promise\PromiseInterface $guzzlePromise
19+
*/
20+
public function __construct(protected PromiseInterface $guzzlePromise)
21+
{
22+
}
23+
24+
#[\Override]
25+
public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface
26+
{
27+
return $this->__call('then', [$onFulfilled, $onRejected]);
28+
}
29+
30+
#[\Override]
31+
public function otherwise(callable $onRejected): PromiseInterface
32+
{
33+
return $this->__call('otherwise', [$onRejected]);
34+
}
35+
36+
#[\Override]
37+
public function resolve($value): void
38+
{
39+
$this->guzzlePromise->resolve($value);
40+
}
41+
42+
#[\Override]
43+
public function reject($reason): void
44+
{
45+
$this->guzzlePromise->reject($reason);
46+
}
47+
48+
#[\Override]
49+
public function cancel(): void
50+
{
51+
$this->guzzlePromise->cancel();
52+
}
53+
54+
#[\Override]
55+
public function wait(bool $unwrap = true)
56+
{
57+
return $this->__call('wait', [$unwrap]);
58+
}
59+
60+
#[\Override]
61+
public function getState(): string
62+
{
63+
return $this->guzzlePromise->getState();
64+
}
65+
66+
/**
67+
* Get the underlying Guzzle promise.
68+
*
69+
* @return \GuzzleHttp\Promise\PromiseInterface
70+
*/
71+
public function getGuzzlePromise(): PromiseInterface
72+
{
73+
return $this->guzzlePromise;
74+
}
75+
76+
/**
77+
* Proxy requests to the underlying promise interface and update the local promise.
78+
*
79+
* @param string $method
80+
* @param array $parameters
81+
* @return mixed
82+
*/
83+
public function __call($method, $parameters)
84+
{
85+
$result = $this->forwardCallTo($this->guzzlePromise, $method, $parameters);
86+
87+
if (! $result instanceof PromiseInterface) {
88+
return $result;
89+
}
90+
91+
$this->guzzlePromise = $result;
92+
93+
return $this;
94+
}
95+
}

0 commit comments

Comments
 (0)