Skip to content

Commit

Permalink
feat: add env maintenance mode driver
Browse files Browse the repository at this point in the history
  • Loading branch information
limwa committed Aug 5, 2024
1 parent 958635b commit aa6af23
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
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 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

0 comments on commit aa6af23

Please sign in to comment.