file_exists($this->flagPath()), ]); } #[Route('/api/admin/maintenance', name: 'admin_maintenance_status', methods: ['GET'])] public function status(): JsonResponse { $this->denyAccessUnlessGranted('ROLE_ADMIN'); return new JsonResponse([ 'enabled' => file_exists($this->flagPath()), ]); } #[Route('/api/admin/maintenance', name: 'admin_maintenance_toggle', methods: ['PUT'])] public function toggle(): JsonResponse { $this->denyAccessUnlessGranted('ROLE_ADMIN'); $path = $this->flagPath(); if (file_exists($path)) { unlink($path); $enabled = false; } else { file_put_contents($path, (string) time()); $enabled = true; } return new JsonResponse(['enabled' => $enabled]); } private function flagPath(): string { return $this->kernel->getProjectDir().'/var/maintenance'; } }