getMaintenanceFilePath(); if (null === $maintenancePath) { throw new BadRequestHttpException('Maintenance file path is not configured for this environment.'); } $requestData = $context['request']?->toArray() ?? []; $enableMaintenance = $requestData['maintenance'] ?? false; if ($enableMaintenance) { $directory = dirname($maintenancePath); if (!is_dir($directory) && !mkdir($directory, 0755, true)) { throw new \RuntimeException(sprintf('Cannot create directory "%s".', $directory)); } if (!touch($maintenancePath)) { throw new \RuntimeException(sprintf('Cannot create maintenance file at "%s".', $maintenancePath)); } } elseif (file_exists($maintenancePath)) { if (!unlink($maintenancePath)) { throw new \RuntimeException(sprintf('Cannot remove maintenance file at "%s".', $maintenancePath)); } } return $data; } }