check(app()->environment('production'), 'APP_ENV=production'); $this->check(! config('app.debug'), 'APP_DEBUG=false'); $this->check(filled(config('app.key')), 'APP_KEY definida'); $https = str_starts_with((string) config('app.url'), 'https://'); $this->check($https, 'APP_URL em https'); $this->check(! $https || config('session.secure') === true, 'SESSION_SECURE_COOKIE=true'); $this->check(! in_array(config('session.driver'), ['array', 'cookie'], true), 'Sessões persistentes (SESSION_DRIVER)'); $this->check(config('cache.default') !== 'array', 'Cache persistente (CACHE_STORE)'); $this->database($migrator); $this->check(Features::enabled(Features::twoFactorAuthentication()), 'MFA ligado (SGC_TWO_FACTOR_ENABLED=true)'); $this->check(array_filter((array) config('mfa.required_functions')) !== [], 'Funções com MFA obrigatório (SGC_MFA_REQUIRED_FUNCTIONS)'); foreach ([storage_path('app/private'), storage_path('logs'), storage_path('framework/sessions'), base_path('bootstrap/cache')] as $path) { $this->check(is_dir($path) && is_writable($path), 'Pasta gravável: '.str_replace(base_path().'/', '', $path)); } $runtime = new Process([PHP_BINARY, base_path('scripts/check-runtime-packages.php')], base_path()); $runtime->run(); $this->check($runtime->isSuccessful(), 'Pacotes partilhados conferidos (runtime:check)'); if (in_array(config('mail.default'), ['log', 'array'], true)) { $this->warn('AVISO Email não configurado (MAIL_MAILER='.config('mail.default').'): avisos de prazos não saem da aplicação.'); } $modules = collect(app(ProductModules::class)->states())->map(fn (bool $on, string $key) => $key.'='.($on ? 'ligado' : 'desligado'))->implode(', '); $this->line('INFO Módulos: '.$modules.'; cancelamento de ordens='.(config('order_cancellation.enabled') ? 'ligado' : 'desligado')); $this->line('INFO Confirme também: cron com `php artisan schedule:run` a cada minuto e cópias de segurança diárias (docs/producao.md).'); if ($this->failures > 0) { $this->error($this->failures.' verificação(ões) falharam. A instalação não está pronta para produção.'); return self::FAILURE; } $this->info('Instalação pronta para produção. Não substitui o restauro de teste nem a aceitação do piloto.'); return self::SUCCESS; } private function database(Migrator $migrator): void { try { DB::connection()->getPdo(); } catch (Throwable) { $this->check(false, 'Ligação à base de dados'); return; } $this->check(DB::connection()->getDriverName() === 'pgsql', 'Base de dados PostgreSQL'); if (! $migrator->repositoryExists()) { $this->check(false, 'Tabela de migrações presente'); return; } $files = $migrator->getMigrationFiles([database_path('migrations'), ...$migrator->paths()]); $pending = array_diff(array_keys($files), $migrator->getRepository()->getRan()); $this->check($pending === [], $pending === [] ? 'Migrações aplicadas' : 'Migrações pendentes: '.count($pending).' ('.implode(', ', array_slice($pending, 0, 3)).')'); } private function check(bool $passed, string $label): void { if ($passed) { $this->line('OK '.$label); return; } $this->failures++; $this->line('FALHA '.$label); } }