CaiWuXiTong/app/Console/Commands/ApplicationReady.php

45 lines
1.0 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Throwable;
class ApplicationReady extends Command
{
protected $signature = 'app:ready';
protected $description = '检查应用安装、运行目录和数据库是否已经可用';
public function handle(): int
{
if (! config('app.installed')) {
return self::FAILURE;
}
try {
foreach ([
storage_path('app'),
storage_path('framework/views'),
storage_path('logs'),
base_path('bootstrap/cache'),
base_path('.env'),
] as $writablePath) {
if (! is_writable($writablePath)) {
return self::FAILURE;
}
}
DB::selectOne('SELECT 1');
} catch (Throwable) {
return self::FAILURE;
}
$this->components->info('应用已就绪。');
return self::SUCCESS;
}
}