Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Make WordPress request handling opt-in & configurable (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x authored Dec 5, 2024
2 parents 8420bc0 + e9896ce commit 88096b5
Show file tree
Hide file tree
Showing 72 changed files with 1,359 additions and 305 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"illuminate/console": "^11.0",
"illuminate/container": "^11.0",
"illuminate/contracts": "^11.0",
"illuminate/cookie": "^11.0",
"illuminate/database": "^11.0",
"illuminate/encryption": "^11.0",
"illuminate/events": "^11.0",
Expand Down
31 changes: 23 additions & 8 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Application extends Container implements ApplicationContract, CachesConfig
*
* @var string
*/
const VERSION = '11.15.0';
const VERSION = '11.34.2';

/**
* The base path for the Laravel installation.
Expand Down Expand Up @@ -759,7 +759,9 @@ public function isProduction()
*/
public function detectEnvironment(Closure $callback)
{
$args = $_SERVER['argv'] ?? null;
$args = $this->runningInConsole() && isset($_SERVER['argv'])
? $_SERVER['argv']
: null;

return $this['env'] = (new EnvironmentDetector)->detect($callback, $args);
}
Expand Down Expand Up @@ -1426,7 +1428,7 @@ public function terminate()
/**
* Get the service providers that have been loaded.
*
* @return array<string, boolean>
* @return array<string, bool>
*/
public function getLoadedProviders()
{
Expand Down Expand Up @@ -1465,6 +1467,17 @@ public function setDeferredServices(array $services)
$this->deferredServices = $services;
}

/**
* Determine if the given service is a deferred service.
*
* @param string $service
* @return bool
*/
public function isDeferredService($service)
{
return isset($this->deferredServices[$service]);
}

/**
* Add an array of services to the application's deferred services.
*
Expand All @@ -1477,14 +1490,16 @@ public function addDeferredServices(array $services)
}

/**
* Determine if the given service is a deferred service.
* Remove an array of services from the application's deferred services.
*
* @param string $service
* @return bool
* @param array $services
* @return void
*/
public function isDeferredService($service)
public function removeDeferredServices(array $services)
{
return isset($this->deferredServices[$service]);
foreach ($services as $service) {
unset($this->deferredServices[$service]);
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Foundation/Auth/Access/Authorizable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait Authorizable
/**
* Determine if the entity has the given abilities.
*
* @param iterable|string $abilities
* @param iterable|\BackedEnum|string $abilities
* @param array|mixed $arguments
* @return bool
*/
Expand All @@ -21,7 +21,7 @@ public function can($abilities, $arguments = [])
/**
* Determine if the entity has any of the given abilities.
*
* @param iterable|string $abilities
* @param iterable|\BackedEnum|string $abilities
* @param array|mixed $arguments
* @return bool
*/
Expand All @@ -33,7 +33,7 @@ public function canAny($abilities, $arguments = [])
/**
* Determine if the entity does not have the given abilities.
*
* @param iterable|string $abilities
* @param iterable|\BackedEnum|string $abilities
* @param array|mixed $arguments
* @return bool
*/
Expand All @@ -45,7 +45,7 @@ public function cant($abilities, $arguments = [])
/**
* Determine if the entity does not have the given abilities.
*
* @param iterable|string $abilities
* @param iterable|\BackedEnum|string $abilities
* @param array|mixed $arguments
* @return bool
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Support\Str;

use function Illuminate\Support\enum_value;

trait AuthorizesRequests
{
/**
Expand Down Expand Up @@ -49,6 +51,8 @@ public function authorizeForUser($user, $ability, $arguments = [])
*/
protected function parseAbilityAndArguments($ability, $arguments)
{
$ability = enum_value($ability);

if (is_string($ability) && ! str_contains($ability, '\\')) {
return [$ability, $arguments];
}
Expand Down
25 changes: 25 additions & 0 deletions src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Log\LogManager;
use Illuminate\Support\Env;
use Monolog\Formatter\JsonFormatter;
use Monolog\Handler\NullHandler;
use Monolog\Handler\SocketHandler;
use PHPUnit\Runner\ErrorHandler;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\ErrorHandler\Error\FatalError;
Expand Down Expand Up @@ -53,6 +55,10 @@ public function bootstrap(Application $app)
if (! $app->environment('testing')) {
ini_set('display_errors', 'Off');
}

if (laravel_cloud()) {
$this->configureCloudSocketLogChannel($app);
}
}

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

/**
* Configure the Laravel Cloud socket log channel.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
protected function configureCloudSocketLogChannel(Application $app)
{
$app['config']->set('logging.channels.laravel-cloud-socket', [
'driver' => 'monolog',
'handler' => SocketHandler::class,
'formatter' => JsonFormatter::class,
'with' => [
'connectionString' => $_ENV['LARAVEL_CLOUD_LOG_SOCKET'] ?? '127.0.0.1:8765',
'persistent' => true,
],
]);
}

/**
* Forward a method call to the given method if an application instance exists.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function loadConfigurationFiles(Application $app, RepositoryContract $
*/
protected function loadConfigurationFile(RepositoryContract $repository, $name, $path, array $base)
{
$config = require $path;
$config = (fn () => require $path)();

if (isset($base[$name])) {
$config = array_merge($base[$name], $config);
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Foundation/Bus/PendingChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Illuminate\Support\Traits\Conditionable;
use Laravel\SerializableClosure\SerializableClosure;

use function Illuminate\Support\enum_value;

class PendingChain
{
use Conditionable;
Expand Down Expand Up @@ -83,12 +85,12 @@ public function onConnection($connection)
/**
* Set the desired queue for the job.
*
* @param string|null $queue
* @param \BackedEnum|string|null $queue
* @return $this
*/
public function onQueue($queue)
{
$this->queue = $queue;
$this->queue = enum_value($queue);

return $this;
}
Expand Down
20 changes: 16 additions & 4 deletions src/Illuminate/Foundation/Bus/PendingDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct($job)
/**
* Set the desired connection for the job.
*
* @param string|null $connection
* @param \BackedEnum|string|null $connection
* @return $this
*/
public function onConnection($connection)
Expand All @@ -51,7 +51,7 @@ public function onConnection($connection)
/**
* Set the desired queue for the job.
*
* @param string|null $queue
* @param \BackedEnum|string|null $queue
* @return $this
*/
public function onQueue($queue)
Expand All @@ -64,7 +64,7 @@ public function onQueue($queue)
/**
* Set the desired connection for the chain.
*
* @param string|null $connection
* @param \BackedEnum|string|null $connection
* @return $this
*/
public function allOnConnection($connection)
Expand All @@ -77,7 +77,7 @@ public function allOnConnection($connection)
/**
* Set the desired queue for the chain.
*
* @param string|null $queue
* @param \BackedEnum|string|null $queue
* @return $this
*/
public function allOnQueue($queue)
Expand All @@ -100,6 +100,18 @@ public function delay($delay)
return $this;
}

/**
* Set the delay for the job to zero seconds.
*
* @return $this
*/
public function withoutDelay()
{
$this->job->withoutDelay();

return $this;
}

/**
* Indicate that the job should be dispatched after all database transactions have committed.
*
Expand Down
45 changes: 42 additions & 3 deletions src/Illuminate/Foundation/Configuration/ApplicationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class ApplicationBuilder
*/
protected array $pendingProviders = [];

/**
* Any additional routing callbacks that should be invoked while registering routes.
*
* @var array
*/
protected array $additionalRoutingCallbacks = [];

/**
* The Folio / page middleware that have been defined by the user.
*
Expand Down Expand Up @@ -203,10 +210,24 @@ protected function buildRoutingCallback(array|string|null $web,
}

if (is_string($health)) {
Route::middleware('web')->get($health, function () {
Event::dispatch(new DiagnosingHealth);
Route::get($health, function () {
$exception = null;

try {
Event::dispatch(new DiagnosingHealth);
} catch (\Throwable $e) {
if (app()->hasDebugModeEnabled()) {
throw $e;
}

report($e);

return View::file(__DIR__.'/../resources/health-up.blade.php');
$exception = $e->getMessage();
}

return response(View::file(__DIR__.'/../resources/health-up.blade.php', [
'exception' => $exception,
]), status: $exception ? 500 : 200);
});
}

Expand All @@ -222,6 +243,10 @@ protected function buildRoutingCallback(array|string|null $web,
}
}

foreach ($this->additionalRoutingCallbacks as $callback) {
$callback();
}

if (is_string($pages) &&
realpath($pages) !== false &&
class_exists(Folio::class)) {
Expand Down Expand Up @@ -258,6 +283,18 @@ public function withMiddleware(?callable $callback = null)
if ($priorities = $middleware->getMiddlewarePriority()) {
$kernel->setMiddlewarePriority($priorities);
}

if ($priorityAppends = $middleware->getMiddlewarePriorityAppends()) {
foreach ($priorityAppends as $newMiddleware => $after) {
$kernel->addToMiddlewarePriorityAfter($after, $newMiddleware);
}
}

if ($priorityPrepends = $middleware->getMiddlewarePriorityPrepends()) {
foreach ($priorityPrepends as $newMiddleware => $before) {
$kernel->addToMiddlewarePriorityBefore($before, $newMiddleware);
}
}
});

return $this;
Expand Down Expand Up @@ -300,6 +337,8 @@ protected function withCommandRouting(array $paths)
$this->app->afterResolving(ConsoleKernel::class, function ($kernel) use ($paths) {
$this->app->booted(fn () => $kernel->addCommandRoutePaths($paths));
});

return $this;
}

/**
Expand Down
Loading

0 comments on commit 88096b5

Please sign in to comment.