Skip to content

[12.x] Add maintenance mode facade for easier driver extension #56090

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

Merged
merged 7 commits into from
Jun 23, 2025

Conversation

ziadoz
Copy link
Contributor

@ziadoz ziadoz commented Jun 20, 2025

I was trying to register a new maintenance mode driver in my app, and noticed a paper cut.

This PR adds a facade for maintenance mode, so a new driver can be registered by doing:

MaintenanceMode::extend('test', fn () => ...);

Instead of having to retrieve the underlying manager class:

$this->app->get(MaintenanceModeManager::class)->extend('test', fn () => ...);

This matches up with elsewhere in Laravel, like Mail::extend(...) and Storage::extend(...).

It also binds maintenance and maintenance.manager strings into the container, so they can be used to retrieve the current maintenance mode driver and manager, like other core dependencies. FQNs still work like before.

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@ziadoz ziadoz marked this pull request as ready for review June 20, 2025 13:01
@ziadoz ziadoz changed the title [12.x] Add maintenance mode facade for easier driver extending [12.x] Add maintenance mode facade for easier driver extension Jun 20, 2025
$this->app->singleton(MaintenanceModeManager::class);
$this->app->singleton('maintenance.manager', function ($app) {
return new MaintenanceModeManager($app);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to assign it a string name that is different than the class name. This could be a breaking change. You can just keep using the class name as the binding name.

Copy link
Contributor Author

@ziadoz ziadoz Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorotwell I was matching up how other managers and drivers are bound in the container here. The core aliases registered in Application above ensure class names still work:

Before:

dump(resolve(\Illuminate\Foundation\MaintenanceModeManager::class)::class); // Illuminate\Foundation\MaintenanceModeManager
dump(resolve(\Illuminate\Contracts\Foundation\MaintenanceMode::class)::class); // Illuminate\Foundation\FileBasedMaintenanceMode

After:

dump(resolve(\Illuminate\Foundation\MaintenanceModeManager::class)::class); // Illuminate\Foundation\MaintenanceModeManager
dump(resolve(\Illuminate\Contracts\Foundation\MaintenanceMode::class)::class); // Illuminate\Foundation\FileBasedMaintenanceMode

Perhaps I've missed something though?

@taylorotwell taylorotwell marked this pull request as draft June 22, 2025 23:40
@ziadoz
Copy link
Contributor Author

ziadoz commented Jun 23, 2025

Have reverted the container binding changes here. Maybe they'd be acceptable for 13.x instead?

@ziadoz ziadoz marked this pull request as ready for review June 23, 2025 09:01
@taylorotwell taylorotwell merged commit 5528074 into laravel:12.x Jun 23, 2025
60 checks passed
@ziadoz ziadoz deleted the maintenance-mode-facade branch June 23, 2025 23:04
mohammad-fouladgar pushed a commit to mohammad-fouladgar/framework that referenced this pull request Jul 22, 2025
…el#56090)

* maintenance mode facade

* alias in provider

* fix bindings

* fix cs

* noop driver

* different cs to pint

* revert container binding changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants