Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Console | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| maintenanceDisplay | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| productionDisplay | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (http://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/pop-bootstrap |
| 7 | * @author Nick Sagona, III <nick@noladev.com> |
| 8 | * @copyright Copyright (c) 2012-2025 NOLA Interactive, LLC. |
| 9 | * @license http://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Kettle\Event; |
| 16 | |
| 17 | use Pop\App; |
| 18 | use Pop\Kettle\Model\Application; |
| 19 | |
| 20 | /** |
| 21 | * Console event class |
| 22 | * |
| 23 | * @category Pop\Kettle |
| 24 | * @package Pop\Kettle |
| 25 | * @author Nick Sagona, III <dev@noladev.com> |
| 26 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 27 | * @license http://www.popphp.org/license New BSD License |
| 28 | * @version 3.0.0 |
| 29 | */ |
| 30 | class Console |
| 31 | { |
| 32 | |
| 33 | /** |
| 34 | * Production check omit commands |
| 35 | * @var array |
| 36 | */ |
| 37 | protected static array $omitCommands = [ |
| 38 | 'app:env', 'app:status', 'help', 'version', 'queue:jobs', 'queue:tasks', 'queue:work', 'queue:scheduler' |
| 39 | ]; |
| 40 | |
| 41 | /** |
| 42 | * Display maintenance alert |
| 43 | * |
| 44 | * @param ?\Pop\Console\Console $console |
| 45 | * @return void |
| 46 | */ |
| 47 | public static function maintenanceDisplay(?\Pop\Console\Console $console = null): void |
| 48 | { |
| 49 | $console = $console ?? new \Pop\Console\Console(); |
| 50 | $routeString = App::get()->router()->getRouteMatch()->getRouteString(); |
| 51 | |
| 52 | if (App::isDown() && ($routeString != 'app:up')) { |
| 53 | $console->alertInfo('Application in Maintenance', 40); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Display production alert and prompt |
| 59 | * |
| 60 | * @param ?\Pop\Console\Console $console |
| 61 | * @return void |
| 62 | */ |
| 63 | public static function productionDisplay(?\Pop\Console\Console $console = null): void |
| 64 | { |
| 65 | $console = $console ?? new \Pop\Console\Console(); |
| 66 | $routeString = App::get()->router()->getRouteMatch()->getRouteString(); |
| 67 | |
| 68 | if ((App::isProduction()) && !in_array($routeString, self::$omitCommands)) { |
| 69 | $console->alertWarning('Application in Production', 40); |
| 70 | $console->confirm('Are you sure you want to run this command?'); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | } |