<?php
 namespace App\Http\Controllers\Install; use App\Actions\Install\RunInstall; use App\Http\Controllers\Controller; use App\Services\Install\RequirementsChecker; use App\Services\License\LicenseService; use Illuminate\Http\Request; class InstallController extends Controller { private const SESSION_KEY = 'install.wizard'; public function requirements(RequirementsChecker $checker) { return view('install.requirements', [ 'step' => 'requirements', 'result' => $checker->run(), ]); } public function license() { return view('install.license', ['step' => 'license', 'data' => $this->data()]); } public function storeLicense(Request $request, LicenseService $license) { $validated = $request->validate([ 'license_key' => ['required', 'string', 'max:191'], ]); $key = trim($validated['license_key']); $fresh = $license->refresh($key); if ($fresh !== null && empty($fresh['payload']['valid'])) { $status = $fresh['payload']['status'] ?? 'invalid'; return back()->withInput()->with('error', "Lisans doğrulanamadı ({$status}). Anahtarı kontrol edin veya destekle iletişime geçin."); } $this->merge(['license_key' => $key]); $notice = $fresh === null ? 'Lisans sunucusuna şu an ulaşılamadı; kuruluma devam edilebilir (grace penceresinde doğrulanacak).' : 'Lisans doğrulandı.'; return redirect()->route('install.application')->with('status', $notice); } public function application(Request $request) { return view('install.application', [ 'step' => 'application', 'data' => $this->data(), 'detectedUrl' => $request->getSchemeAndHttpHost(), ]); } public function storeApplication(Request $request) { $validated = $request->validate([ 'site_name' => ['required', 'string', 'max:191'], 'app_url' => ['required', 'url', 'max:191'], 'timezone' => ['required', 'string', 'max:64', 'timezone'], 'locale' => ['required', 'string', 'in:tr,en'], ]); $this->merge($validated); return redirect()->route('install.admin'); } public function admin() { return view('install.admin', ['step' => 'admin', 'data' => $this->data()]); } public function storeAdmin(Request $request) { $validated = $request->validate([ 'admin_name' => ['required', 'string', 'max:191'], 'admin_email' => ['required', 'email', 'max:191'], 'admin_password' => ['required', 'string', 'min:8', 'confirmed'], ]); $this->merge($validated); return redirect()->route('install.review'); } public function review() { $data = $this->data(); if (empty($data['admin_email']) || empty($data['site_name'])) { return redirect()->route('install.requirements')->with('error', 'Lütfen tüm adımları tamamlayın.'); } return view('install.review', ['step' => 'review', 'data' => $data]); } public function run() { $data = $this->data(); if (empty($data['admin_email'])) { return redirect()->route('install.requirements')->with('error', 'Eksik kurulum verisi.'); } app(RunInstall::class)->execute($data); session()->forget(self::SESSION_KEY); return view('install.complete', [ 'step' => 'complete', 'loginUrl' => route('admin.login'), ]); } private function data(): array { return (array) session(self::SESSION_KEY, []); } private function merge(array $values): void { session([self::SESSION_KEY => array_merge($this->data(), $values)]); } } 