Skip to content

Commit 88096b5

Browse files
authored
πŸ§‘β€πŸ’» Make WordPress request handling opt-in & configurable (#416)
2 parents 8420bc0 + e9896ce commit 88096b5

File tree

72 files changed

+1359
-305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1359
-305
lines changed

β€Žcomposer.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"illuminate/console": "^11.0",
5252
"illuminate/container": "^11.0",
5353
"illuminate/contracts": "^11.0",
54+
"illuminate/cookie": "^11.0",
5455
"illuminate/database": "^11.0",
5556
"illuminate/encryption": "^11.0",
5657
"illuminate/events": "^11.0",

β€Žsrc/Illuminate/Foundation/Application.phpβ€Ž

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Application extends Container implements ApplicationContract, CachesConfig
4545
*
4646
* @var string
4747
*/
48-
const VERSION = '11.15.0';
48+
const VERSION = '11.34.2';
4949

5050
/**
5151
* The base path for the Laravel installation.
@@ -759,7 +759,9 @@ public function isProduction()
759759
*/
760760
public function detectEnvironment(Closure $callback)
761761
{
762-
$args = $_SERVER['argv'] ?? null;
762+
$args = $this->runningInConsole() && isset($_SERVER['argv'])
763+
? $_SERVER['argv']
764+
: null;
763765

764766
return $this['env'] = (new EnvironmentDetector)->detect($callback, $args);
765767
}
@@ -1426,7 +1428,7 @@ public function terminate()
14261428
/**
14271429
* Get the service providers that have been loaded.
14281430
*
1429-
* @return array<string, boolean>
1431+
* @return array<string, bool>
14301432
*/
14311433
public function getLoadedProviders()
14321434
{
@@ -1465,6 +1467,17 @@ public function setDeferredServices(array $services)
14651467
$this->deferredServices = $services;
14661468
}
14671469

1470+
/**
1471+
* Determine if the given service is a deferred service.
1472+
*
1473+
* @param string $service
1474+
* @return bool
1475+
*/
1476+
public function isDeferredService($service)
1477+
{
1478+
return isset($this->deferredServices[$service]);
1479+
}
1480+
14681481
/**
14691482
* Add an array of services to the application's deferred services.
14701483
*
@@ -1477,14 +1490,16 @@ public function addDeferredServices(array $services)
14771490
}
14781491

14791492
/**
1480-
* Determine if the given service is a deferred service.
1493+
* Remove an array of services from the application's deferred services.
14811494
*
1482-
* @param string $service
1483-
* @return bool
1495+
* @param array $services
1496+
* @return void
14841497
*/
1485-
public function isDeferredService($service)
1498+
public function removeDeferredServices(array $services)
14861499
{
1487-
return isset($this->deferredServices[$service]);
1500+
foreach ($services as $service) {
1501+
unset($this->deferredServices[$service]);
1502+
}
14881503
}
14891504

14901505
/**

β€Žsrc/Illuminate/Foundation/Auth/Access/Authorizable.phpβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait Authorizable
99
/**
1010
* Determine if the entity has the given abilities.
1111
*
12-
* @param iterable|string $abilities
12+
* @param iterable|\BackedEnum|string $abilities
1313
* @param array|mixed $arguments
1414
* @return bool
1515
*/
@@ -21,7 +21,7 @@ public function can($abilities, $arguments = [])
2121
/**
2222
* Determine if the entity has any of the given abilities.
2323
*
24-
* @param iterable|string $abilities
24+
* @param iterable|\BackedEnum|string $abilities
2525
* @param array|mixed $arguments
2626
* @return bool
2727
*/
@@ -33,7 +33,7 @@ public function canAny($abilities, $arguments = [])
3333
/**
3434
* Determine if the entity does not have the given abilities.
3535
*
36-
* @param iterable|string $abilities
36+
* @param iterable|\BackedEnum|string $abilities
3737
* @param array|mixed $arguments
3838
* @return bool
3939
*/
@@ -45,7 +45,7 @@ public function cant($abilities, $arguments = [])
4545
/**
4646
* Determine if the entity does not have the given abilities.
4747
*
48-
* @param iterable|string $abilities
48+
* @param iterable|\BackedEnum|string $abilities
4949
* @param array|mixed $arguments
5050
* @return bool
5151
*/

β€Žsrc/Illuminate/Foundation/Auth/Access/AuthorizesRequests.phpβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Illuminate\Contracts\Auth\Access\Gate;
66
use Illuminate\Support\Str;
77

8+
use function Illuminate\Support\enum_value;
9+
810
trait AuthorizesRequests
911
{
1012
/**
@@ -49,6 +51,8 @@ public function authorizeForUser($user, $ability, $arguments = [])
4951
*/
5052
protected function parseAbilityAndArguments($ability, $arguments)
5153
{
54+
$ability = enum_value($ability);
55+
5256
if (is_string($ability) && ! str_contains($ability, '\\')) {
5357
return [$ability, $arguments];
5458
}

β€Žsrc/Illuminate/Foundation/Bootstrap/HandleExceptions.phpβ€Ž

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Illuminate\Contracts\Foundation\Application;
99
use Illuminate\Log\LogManager;
1010
use Illuminate\Support\Env;
11+
use Monolog\Formatter\JsonFormatter;
1112
use Monolog\Handler\NullHandler;
13+
use Monolog\Handler\SocketHandler;
1214
use PHPUnit\Runner\ErrorHandler;
1315
use Symfony\Component\Console\Output\ConsoleOutput;
1416
use Symfony\Component\ErrorHandler\Error\FatalError;
@@ -53,6 +55,10 @@ public function bootstrap(Application $app)
5355
if (! $app->environment('testing')) {
5456
ini_set('display_errors', 'Off');
5557
}
58+
59+
if (laravel_cloud()) {
60+
$this->configureCloudSocketLogChannel($app);
61+
}
5662
}
5763

5864
/**
@@ -245,6 +251,25 @@ protected function fatalErrorFromPhpError(array $error, $traceOffset = null)
245251
return new FatalError($error['message'], 0, $error, $traceOffset);
246252
}
247253

254+
/**
255+
* Configure the Laravel Cloud socket log channel.
256+
*
257+
* @param \Illuminate\Contracts\Foundation\Application $app
258+
* @return void
259+
*/
260+
protected function configureCloudSocketLogChannel(Application $app)
261+
{
262+
$app['config']->set('logging.channels.laravel-cloud-socket', [
263+
'driver' => 'monolog',
264+
'handler' => SocketHandler::class,
265+
'formatter' => JsonFormatter::class,
266+
'with' => [
267+
'connectionString' => $_ENV['LARAVEL_CLOUD_LOG_SOCKET'] ?? '127.0.0.1:8765',
268+
'persistent' => true,
269+
],
270+
]);
271+
}
272+
248273
/**
249274
* Forward a method call to the given method if an application instance exists.
250275
*

β€Žsrc/Illuminate/Foundation/Bootstrap/LoadConfiguration.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function loadConfigurationFiles(Application $app, RepositoryContract $
9393
*/
9494
protected function loadConfigurationFile(RepositoryContract $repository, $name, $path, array $base)
9595
{
96-
$config = require $path;
96+
$config = (fn () => require $path)();
9797

9898
if (isset($base[$name])) {
9999
$config = array_merge($base[$name], $config);

β€Žsrc/Illuminate/Foundation/Bus/PendingChain.phpβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Illuminate\Support\Traits\Conditionable;
99
use Laravel\SerializableClosure\SerializableClosure;
1010

11+
use function Illuminate\Support\enum_value;
12+
1113
class PendingChain
1214
{
1315
use Conditionable;
@@ -83,12 +85,12 @@ public function onConnection($connection)
8385
/**
8486
* Set the desired queue for the job.
8587
*
86-
* @param string|null $queue
88+
* @param \BackedEnum|string|null $queue
8789
* @return $this
8890
*/
8991
public function onQueue($queue)
9092
{
91-
$this->queue = $queue;
93+
$this->queue = enum_value($queue);
9294

9395
return $this;
9496
}

β€Žsrc/Illuminate/Foundation/Bus/PendingDispatch.phpβ€Ž

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct($job)
3838
/**
3939
* Set the desired connection for the job.
4040
*
41-
* @param string|null $connection
41+
* @param \BackedEnum|string|null $connection
4242
* @return $this
4343
*/
4444
public function onConnection($connection)
@@ -51,7 +51,7 @@ public function onConnection($connection)
5151
/**
5252
* Set the desired queue for the job.
5353
*
54-
* @param string|null $queue
54+
* @param \BackedEnum|string|null $queue
5555
* @return $this
5656
*/
5757
public function onQueue($queue)
@@ -64,7 +64,7 @@ public function onQueue($queue)
6464
/**
6565
* Set the desired connection for the chain.
6666
*
67-
* @param string|null $connection
67+
* @param \BackedEnum|string|null $connection
6868
* @return $this
6969
*/
7070
public function allOnConnection($connection)
@@ -77,7 +77,7 @@ public function allOnConnection($connection)
7777
/**
7878
* Set the desired queue for the chain.
7979
*
80-
* @param string|null $queue
80+
* @param \BackedEnum|string|null $queue
8181
* @return $this
8282
*/
8383
public function allOnQueue($queue)
@@ -100,6 +100,18 @@ public function delay($delay)
100100
return $this;
101101
}
102102

103+
/**
104+
* Set the delay for the job to zero seconds.
105+
*
106+
* @return $this
107+
*/
108+
public function withoutDelay()
109+
{
110+
$this->job->withoutDelay();
111+
112+
return $this;
113+
}
114+
103115
/**
104116
* Indicate that the job should be dispatched after all database transactions have committed.
105117
*

β€Žsrc/Illuminate/Foundation/Configuration/ApplicationBuilder.phpβ€Ž

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class ApplicationBuilder
2727
*/
2828
protected array $pendingProviders = [];
2929

30+
/**
31+
* Any additional routing callbacks that should be invoked while registering routes.
32+
*
33+
* @var array
34+
*/
35+
protected array $additionalRoutingCallbacks = [];
36+
3037
/**
3138
* The Folio / page middleware that have been defined by the user.
3239
*
@@ -203,10 +210,24 @@ protected function buildRoutingCallback(array|string|null $web,
203210
}
204211

205212
if (is_string($health)) {
206-
Route::middleware('web')->get($health, function () {
207-
Event::dispatch(new DiagnosingHealth);
213+
Route::get($health, function () {
214+
$exception = null;
215+
216+
try {
217+
Event::dispatch(new DiagnosingHealth);
218+
} catch (\Throwable $e) {
219+
if (app()->hasDebugModeEnabled()) {
220+
throw $e;
221+
}
222+
223+
report($e);
208224

209-
return View::file(__DIR__.'/../resources/health-up.blade.php');
225+
$exception = $e->getMessage();
226+
}
227+
228+
return response(View::file(__DIR__.'/../resources/health-up.blade.php', [
229+
'exception' => $exception,
230+
]), status: $exception ? 500 : 200);
210231
});
211232
}
212233

@@ -222,6 +243,10 @@ protected function buildRoutingCallback(array|string|null $web,
222243
}
223244
}
224245

246+
foreach ($this->additionalRoutingCallbacks as $callback) {
247+
$callback();
248+
}
249+
225250
if (is_string($pages) &&
226251
realpath($pages) !== false &&
227252
class_exists(Folio::class)) {
@@ -258,6 +283,18 @@ public function withMiddleware(?callable $callback = null)
258283
if ($priorities = $middleware->getMiddlewarePriority()) {
259284
$kernel->setMiddlewarePriority($priorities);
260285
}
286+
287+
if ($priorityAppends = $middleware->getMiddlewarePriorityAppends()) {
288+
foreach ($priorityAppends as $newMiddleware => $after) {
289+
$kernel->addToMiddlewarePriorityAfter($after, $newMiddleware);
290+
}
291+
}
292+
293+
if ($priorityPrepends = $middleware->getMiddlewarePriorityPrepends()) {
294+
foreach ($priorityPrepends as $newMiddleware => $before) {
295+
$kernel->addToMiddlewarePriorityBefore($before, $newMiddleware);
296+
}
297+
}
261298
});
262299

263300
return $this;
@@ -300,6 +337,8 @@ protected function withCommandRouting(array $paths)
300337
$this->app->afterResolving(ConsoleKernel::class, function ($kernel) use ($paths) {
301338
$this->app->booted(fn () => $kernel->addCommandRoutePaths($paths));
302339
});
340+
341+
return $this;
303342
}
304343

305344
/**

0 commit comments

Comments
Β (0)