Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e230133
chore (maintenance): move maintenance mode logic
Dec 15, 2021
09031d4
refactor (maintenance): add isUp method
Dec 16, 2021
29aaa45
doc (maintenance): document code
Dec 16, 2021
113f193
fix (maintenance): correctly check if in maintenance
Dec 16, 2021
c99e067
refactor (maintenance): use make method
Dec 16, 2021
27d5c68
doc (maintenance): update docblock
Dec 16, 2021
48aa9ff
doc (maintenance): update docblock
Dec 16, 2021
f66ba1c
style (doc): update documentation style
Dec 16, 2021
1ee6193
style (doc): update documentation style
Dec 16, 2021
6ec23f6
refactor (maintenance): change namespace
Dec 16, 2021
10ff03a
style (doc): update documentation style
Dec 16, 2021
10d2020
style (doc): update documentation style
Dec 16, 2021
1835d14
Update src/Illuminate/Foundation/Http/Middleware/PreventRequestsDurin…
wimulkeman Dec 16, 2021
b15b8d1
Update src/Illuminate/Foundation/Http/Middleware/PreventRequestsDurin…
wimulkeman Dec 16, 2021
7f3d335
refactor (maintenance): move to application
Dec 16, 2021
59e4e7e
doc (maintenance): add DockBlock
Dec 16, 2021
1e9633f
refactor (maintenance): use application method
Dec 16, 2021
614c6a0
Update src/Illuminate/Foundation/MaintenanceMode.php
wimulkeman Dec 16, 2021
45c9236
Update src/Illuminate/Foundation/MaintenanceMode.php
wimulkeman Dec 16, 2021
2121afb
refactor (maintenance): remove comparison
Dec 16, 2021
2ec1619
chore (code): remove unused import
Dec 16, 2021
040d691
refactor (maintenance): add interface
Dec 16, 2021
b17e090
style (doc): update documentation style
Dec 16, 2021
8dd9f7a
refactor (maintenance): bind instance to contract
Dec 17, 2021
838f09c
style (doc): update documentation style
Dec 17, 2021
c617f62
Update src/Illuminate/Foundation/Providers/FoundationServiceProvider.php
wimulkeman Dec 17, 2021
54ce40c
formatting and renaming
taylorotwell Dec 17, 2021
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
7 changes: 7 additions & 0 deletions src/Illuminate/Contracts/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public function runningInConsole();
*/
public function runningUnitTests();

/**
* Get an instance of the maintenance mode manager implementation.
*
* @return \Illuminate\Contracts\Foundation\MaintenanceMode
*/
public function maintenanceMode();

/**
* Determine if the application is currently down for maintenance.
*
Expand Down
35 changes: 35 additions & 0 deletions src/Illuminate/Contracts/Foundation/MaintenanceMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Illuminate\Contracts\Foundation;

interface MaintenanceMode
{
/**
* 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;

/**
* Get the data array which was provided when the application was placed into maintenance.
*
* @return array
*/
public function data(): array;
}
13 changes: 12 additions & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Contracts\Foundation\CachesConfiguration;
use Illuminate\Contracts\Foundation\CachesRoutes;
use Illuminate\Contracts\Foundation\MaintenanceMode as MaintenanceModeContract;
use Illuminate\Contracts\Http\Kernel as HttpKernelContract;
use Illuminate\Events\EventServiceProvider;
use Illuminate\Filesystem\Filesystem;
Expand Down Expand Up @@ -1105,14 +1106,24 @@ public function addAbsoluteCachePathPrefix($prefix)
return $this;
}

/**
* Get an instance of the maintenance mode manager implementation.
*
* @return \Illuminate\Contracts\Foundation\MaintenanceMode
*/
public function maintenanceMode()
{
return $this->make(MaintenanceModeContract::class);
}

/**
* Determine if the application is currently down for maintenance.
*
* @return bool
*/
public function isDownForMaintenance()
{
return file_exists($this->storagePath().'/framework/down');
return $this->maintenanceMode()->active();
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/Illuminate/Foundation/Console/DownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@ class DownCommand extends Command
public function handle()
{
try {
if (is_file(storage_path('framework/down'))) {
if ($this->laravel->maintenanceMode()->active()) {
$this->comment('Application is already down.');

return 0;
}

file_put_contents(
storage_path('framework/down'),
json_encode($this->getDownFilePayload(), JSON_PRETTY_PRINT)
);
$this->laravel->maintenanceMode()->activate($this->getDownFilePayload());

file_put_contents(
storage_path('framework/maintenance.php'),
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Console/UpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class UpCommand extends Command
public function handle()
{
try {
if (! is_file(storage_path('framework/down'))) {
if (! $this->laravel->maintenanceMode()->active()) {
$this->comment('Application is already up.');

return 0;
}

unlink(storage_path('framework/down'));
$this->laravel->maintenanceMode()->deactivate();

if (is_file(storage_path('framework/maintenance.php'))) {
unlink(storage_path('framework/maintenance.php'));
Expand Down
64 changes: 64 additions & 0 deletions src/Illuminate/Foundation/FileBasedMaintenanceMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Illuminate\Foundation;

use Illuminate\Contracts\Foundation\MaintenanceMode as MaintenanceModeContract;

class FileBasedMaintenanceMode implements MaintenanceModeContract
{
/**
* Take the application down for maintenance.
*
* @param array $payload
* @return void
*/
public function activate(array $payload): void
{
file_put_contents(
$this->path(),
json_encode($payload, JSON_PRETTY_PRINT)
);
}

/**
* Take the application out of maintenance.
*
* @return void
*/
public function deactivate(): void
{
if ($this->active()) {
unlink($this->path());
}
}

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

/**
* Get the data array which was provided when the application was placed into maintenance.
*
* @return array
*/
public function data(): array
{
return json_decode(file_get_contents($this->path()), true);
}

/**
* Get the path where the file is stored that signals that the application is down for maintenance.
*
* @return string
*/
protected function path(): string
{
return storage_path('framework/down');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function __construct(Application $app)
*/
public function handle($request, Closure $next)
{
if ($this->app->isDownForMaintenance()) {
$data = json_decode(file_get_contents($this->app->storagePath().'/framework/down'), true);
if ($this->app->maintenanceMode()->active()) {
$data = $this->app->maintenanceMode()->data();

if (isset($data['secret']) && $request->path() === $data['secret']) {
return $this->bypassResponse($data['secret']);
Expand Down
14 changes: 14 additions & 0 deletions src/Illuminate/Foundation/Providers/FoundationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Illuminate\Foundation\Providers;

use Illuminate\Contracts\Foundation\MaintenanceMode as MaintenanceModeContract;
use Illuminate\Foundation\FileBasedMaintenanceMode;
use Illuminate\Foundation\MaintenanceMode;
use Illuminate\Http\Request;
use Illuminate\Log\Events\MessageLogged;
use Illuminate\Support\AggregateServiceProvider;
Expand Down Expand Up @@ -48,6 +51,7 @@ public function register()
$this->registerRequestValidation();
$this->registerRequestSignatureValidation();
$this->registerExceptionTracking();
$this->registerMaintenanceModeManager();
}

/**
Expand Down Expand Up @@ -117,4 +121,14 @@ protected function registerExceptionTracking()
}
});
}

/**
* Register the maintenance mode manager service.
*
* @return void
*/
public function registerMaintenanceModeManager()
{
$this->app->bind(MaintenanceModeContract::class, FileBasedMaintenanceMode::class);
}
}