Skip to content
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

feat: add env maintenance mode driver #29

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Facades\Log;
use Inertia\Inertia;
use Throwable;

Expand Down
48 changes: 48 additions & 0 deletions app/Maintenance/EnvMaintenanceMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Maintenance;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Foundation\MaintenanceMode;

class EnvMaintenanceMode implements MaintenanceMode
{
public function __construct(protected Application $app) {}

/**
* Take the application down for maintenance.
*
* @param array $payload
* @return void
*/
public function activate(array $payload): void {
//
}

/**
* Take the application out of maintenance.
*
* @return void
*/
public function deactivate(): void {
//
}

/**
* Determine if the application is currently down for maintenance.
*
* @return bool
*/
public function active(): bool {
return $this->app->environment(['maintenance']);
}

/**
* Get the data array which was provided when the application was placed into maintenance.
*
* @return array
*/
public function data(): array {
return [];
}
}
17 changes: 16 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace App\Providers;

use App\Maintenance\EnvMaintenanceMode;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\MaintenanceModeManager;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

Expand All @@ -12,7 +16,18 @@ class AppServiceProvider extends ServiceProvider
*/
public function register(): void
{
//
$this->app->extend(
MaintenanceModeManager::class,
function (MaintenanceModeManager $manager) {
$manager->extend('env', function (Container $container) {
return new EnvMaintenanceMode(
$container->make(Application::class)
);
});

return $manager;
}
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
| manage Laravel's "maintenance mode" status. The "cache" driver will
| allow maintenance mode to be controlled across multiple machines.
|
| Supported drivers: "file", "cache"
| Supported drivers: "file", "cache", "env"
|
*/

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
dockerfile: ./dockerfiles/Dockerfile.website
target: deploy
args:
- LARAVEL_ENV=local
- LARAVEL_ENV=${APP_ENV:-local}
- LARAVEL_ENV_FILE=.env
ports:
- '80:80'
Expand Down
Loading