Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/11.x' into defer-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Sep 16, 2024
2 parents 61cd109 + 0d0f55f commit e18346b
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 80 deletions.
2 changes: 1 addition & 1 deletion config/concurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
|
*/

'driver' => env('CONCURRENCY_DRIVER', 'process'),
'default' => env('CONCURRENCY_DRIVER', 'process'),

];
2 changes: 2 additions & 0 deletions phpstan.types.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ parameters:
level: max
paths:
- types
ignoreErrors:
- identifier: argument.templateType
12 changes: 8 additions & 4 deletions src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,11 @@ public function getOrPut($key, $value)
/**
* Group an associative array by a field or using a callback.
*
* @param (callable(TValue, TKey): array-key)|array|string $groupBy
* @template TGroupKey of array-key
*
* @param (callable(TValue, TKey): TGroupKey)|array|string $groupBy
* @param bool $preserveKeys
* @return static<array-key, static<array-key, TValue>>
* @return static<TGroupKey, static<($preserveKeys is true ? TKey : int), TValue>>
*/
public function groupBy($groupBy, $preserveKeys = false)
{
Expand Down Expand Up @@ -537,8 +539,10 @@ public function groupBy($groupBy, $preserveKeys = false)
/**
* Key an associative array by a field or using a callback.
*
* @param (callable(TValue, TKey): array-key)|array|string $keyBy
* @return static<array-key, TValue>
* @template TNewKey of array-key
*
* @param (callable(TValue, TKey): TNewKey)|array|string $keyBy
* @return static<TNewKey, TValue>
*/
public function keyBy($keyBy)
{
Expand Down
12 changes: 8 additions & 4 deletions src/Illuminate/Collections/Enumerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,17 +518,21 @@ public function get($key, $default = null);
/**
* Group an associative array by a field or using a callback.
*
* @param (callable(TValue, TKey): array-key)|array|string $groupBy
* @template TGroupKey of array-key
*
* @param (callable(TValue, TKey): TGroupKey)|array|string $groupBy
* @param bool $preserveKeys
* @return static<array-key, static<array-key, TValue>>
* @return static<TGroupKey, static<($preserveKeys is true ? TKey : int), TValue>>
*/
public function groupBy($groupBy, $preserveKeys = false);

/**
* Key an associative array by a field or using a callback.
*
* @param (callable(TValue, TKey): array-key)|array|string $keyBy
* @return static<array-key, TValue>
* @template TNewKey of array-key
*
* @param (callable(TValue, TKey): TNewKey)|array|string $keyBy
* @return static<TNewKey, TValue>
*/
public function keyBy($keyBy);

Expand Down
12 changes: 8 additions & 4 deletions src/Illuminate/Collections/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,11 @@ public function get($key, $default = null)
/**
* Group an associative array by a field or using a callback.
*
* @param (callable(TValue, TKey): array-key)|array|string $groupBy
* @template TGroupKey of array-key
*
* @param (callable(TValue, TKey): TGroupKey)|array|string $groupBy
* @param bool $preserveKeys
* @return static<array-key, static<array-key, TValue>>
* @return static<TGroupKey, static<($preserveKeys is true ? TKey : int), TValue>>
*/
public function groupBy($groupBy, $preserveKeys = false)
{
Expand All @@ -556,8 +558,10 @@ public function groupBy($groupBy, $preserveKeys = false)
/**
* Key an associative array by a field or using a callback.
*
* @param (callable(TValue, TKey): array-key)|array|string $keyBy
* @return static<array-key, TValue>
* @template TNewKey of array-key
*
* @param (callable(TValue, TKey): TNewKey)|array|string $keyBy
* @return static<TNewKey, TValue>
*/
public function keyBy($keyBy)
{
Expand Down
7 changes: 5 additions & 2 deletions src/Illuminate/Concurrency/ConcurrencyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public function createSyncDriver(array $config)
*/
public function getDefaultInstance()
{
return $this->app['config']['concurrency.default'] ?? 'process';
return $this->app['config']['concurrency.default']
?? $this->app['config']['concurrency.driver']
?? 'process';
}

/**
Expand All @@ -83,6 +85,7 @@ public function getDefaultInstance()
public function setDefaultInstance($name)
{
$this->app['config']['concurrency.default'] = $name;
$this->app['config']['concurrency.driver'] = $name;
}

/**
Expand All @@ -94,7 +97,7 @@ public function setDefaultInstance($name)
public function getInstanceConfig($name)
{
return $this->app['config']->get(
'concurrency.drivers.'.$name, ['driver' => $name],
'concurrency.driver.'.$name, ['driver' => $name],
);
}
}
40 changes: 7 additions & 33 deletions src/Illuminate/Concurrency/ProcessDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace Illuminate\Concurrency;

use Closure;
use Illuminate\Console\Application;
use Illuminate\Contracts\Concurrency\Driver;
use Illuminate\Process\Factory as ProcessFactory;
use Illuminate\Process\Pool;
use Illuminate\Support\Arr;
use Illuminate\Support\Defer\DeferredCallback;
use Laravel\SerializableClosure\SerializableClosure;
use Symfony\Component\Process\PhpExecutableFinder;

use function Illuminate\Support\defer;

Expand All @@ -28,18 +28,13 @@ public function __construct(protected ProcessFactory $processFactory)
*/
public function run(Closure|array $tasks): array
{
$php = $this->phpBinary();
$artisan = $this->artisanBinary();
$command = Application::formatCommandString('invoke-serialized-closure');

$results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $php, $artisan) {
$results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $command) {
foreach (Arr::wrap($tasks) as $task) {
$pool->path(base_path())->env([
'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)),
])->command([
$php,
$artisan,
'invoke-serialized-closure',
]);
])->command($command);
}
})->start()->wait();

Expand All @@ -61,35 +56,14 @@ public function run(Closure|array $tasks): array
*/
public function defer(Closure|array $tasks): DeferredCallback
{
$php = $this->phpBinary();
$artisan = $this->artisanBinary();
$command = Application::formatCommandString('invoke-serialized-closure');

return defer(function () use ($tasks, $php, $artisan) {
return defer(function () use ($tasks, $command) {
foreach (Arr::wrap($tasks) as $task) {
$this->processFactory->path(base_path())->env([
'LARAVEL_INVOKABLE_CLOSURE' => serialize(new SerializableClosure($task)),
])->run([
$php,
$artisan,
'invoke-serialized-closure 2>&1 &',
]);
])->run($command.' 2>&1 &');
}
});
}

/**
* Get the PHP binary.
*/
protected function phpBinary(): string
{
return (new PhpExecutableFinder)->find(false) ?: 'php';
}

/**
* Get the Artisan binary.
*/
protected function artisanBinary(): string
{
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
}
}
10 changes: 5 additions & 5 deletions src/Illuminate/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,11 @@ public function withoutPretending(Closure $callback)

$this->pretending = false;

$result = $callback();

$this->pretending = true;

return $result;
try {
return $callback();
} finally {
$this->pretending = true;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/DetectsLostConnections.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ protected function causedByLostConnection(Throwable $e)
'SSL: Connection timed out',
'SQLSTATE[HY000]: General error: 1105 The last transaction was aborted due to Seamless Scaling. Please retry.',
'Temporary failure in name resolution',
'SSL: Broken pipe',
'SQLSTATE[08S01]: Communication link failure',
'SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host',
'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: No route to host',
Expand All @@ -71,6 +70,7 @@ protected function causedByLostConnection(Throwable $e)
'SQLSTATE[HY000] [2002] Network is unreachable',
'SQLSTATE[HY000] [2002] The requested address is not valid in its context',
'SQLSTATE[HY000] [2002] A socket operation was attempted to an unreachable network',
'SQLSTATE[HY000] [2002] Operation now in progress',
'SQLSTATE[HY000]: General error: 3989',
'went away',
'No such file or directory',
Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Database/Schema/ForeignKeyDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public function restrictOnUpdate()
return $this->onUpdate('restrict');
}

/**
* Indicate that updates should set the foreign key value to null.
*
* @return $this
*/
public function nullOnUpdate()
{
return $this->onUpdate('set null');
}

/**
* Indicate that updates should have "no action".
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Http\Middleware;

use Illuminate\Http\Response;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Vite;

Expand All @@ -17,7 +18,7 @@ class AddLinkHeadersForPreloadedAssets
public function handle($request, $next)
{
return tap($next($request), function ($response) {
if (Vite::preloadedAssets() !== []) {
if ($response instanceof Response && Vite::preloadedAssets() !== []) {
$response->header('Link', Collection::make(Vite::preloadedAssets())
->map(fn ($attributes, $url) => "<{$url}>; ".implode('; ', $attributes))
->join(', '));
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -1081,12 +1081,14 @@ public function middleware($middleware = null)
/**
* Specify that the "Authorize" / "can" middleware should be applied to the route with the given options.
*
* @param string $ability
* @param \BackedEnum|string $ability
* @param array|string $models
* @return $this
*/
public function can($ability, $models = [])
{
$ability = $ability instanceof BackedEnum ? $ability->value : $ability;

return empty($models)
? $this->middleware(['can:'.$ability])
: $this->middleware(['can:'.$ability.','.implode(',', Arr::wrap($models))]);
Expand Down
3 changes: 1 addition & 2 deletions src/Illuminate/Support/Defer/DeferredCallbackCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use ArrayAccess;
use Closure;
use Countable;
use Illuminate\Support\Collection;

class DeferredCallbackCollection implements ArrayAccess, Countable
{
Expand Down Expand Up @@ -39,7 +38,7 @@ public function invoke(): void
/**
* Invoke the deferred callbacks if the given truth test evaluates to true.
*
* @param \Closure $when
* @param \Closure|null $when
* @return void
*/
public function invokeWhen(?Closure $when = null): void
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/Facades/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @method static bool hasRenderedOnce(string $id)
* @method static void markAsRenderedOnce(string $id)
* @method static void addLocation(string $location)
* @method static void prependLocation(string $location)
* @method static \Illuminate\View\Factory addNamespace(string $namespace, string|array $hints)
* @method static \Illuminate\View\Factory prependNamespace(string $namespace, string|array $hints)
* @method static \Illuminate\View\Factory replaceNamespace(string $namespace, string|array $hints)
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/View/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ public function addLocation($location)
$this->finder->addLocation($location);
}

/**
* Prepend a location to the array of view locations.
*
* @param string $location
* @return void
*/
public function prependLocation($location)
{
$this->finder->prependLocation($location);
}

/**
* Add a new namespace to the loader.
*
Expand Down
26 changes: 24 additions & 2 deletions tests/Http/Middleware/VitePreloadingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Facade;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

class VitePreloadingTest extends TestCase
{
Expand All @@ -20,7 +21,7 @@ protected function tearDown(): void

public function testItDoesNotSetLinkTagWhenNoTagsHaveBeenPreloaded()
{
$app = new Container();
$app = new Container;
$app->instance(Vite::class, new class extends Vite
{
protected $preloadedAssets = [];
Expand All @@ -36,7 +37,7 @@ public function testItDoesNotSetLinkTagWhenNoTagsHaveBeenPreloaded()

public function testItAddsPreloadLinkHeader()
{
$app = new Container();
$app = new Container;
$app->instance(Vite::class, new class extends Vite
{
protected $preloadedAssets = [
Expand All @@ -57,4 +58,25 @@ public function testItAddsPreloadLinkHeader()
'<https://laravel.com/app.js>; rel="modulepreload"; foo="bar"'
);
}

public function testItDoesNotAttachHeadersToNonIlluminateResponses()
{
$app = new Container;
$app->instance(Vite::class, new class extends Vite
{
protected $preloadedAssets = [
'https://laravel.com/app.js' => [
'rel="modulepreload"',
'foo="bar"',
],
];
});
Facade::setFacadeApplication($app);

$response = (new AddLinkHeadersForPreloadedAssets)->handle(new Request, function () {
return new SymfonyResponse('Hello Laravel');
});

$this->assertNull($response->headers->get('Link'));
}
}
9 changes: 9 additions & 0 deletions tests/Integration/Routing/AbilityBackedEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Illuminate\Tests\Integration\Routing;

enum AbilityBackedEnum: string
{
case AccessRoute = 'access-route';
case NotAccessRoute = 'not-access-route';
}
Loading

0 comments on commit e18346b

Please sign in to comment.