/** * {@inheritdoc} */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, WatcherInterface $watcher) { if ($watcher instanceof ScheduledWatcherInterface) { $response = $response->withHeader('Expires', $watcher->getEnd()->format('D, d M Y H:i:s e')); } else { $response = $response->withHeader('Cache-Control', 'max-age=0')->withHeader('Cache-Control', 'no-cache, must-revalidate')->withHeader('Pragma', 'no-cache'); } $location = $this->location; if (!preg_match('/^https?:\\/\\//', $location)) { $location = (string) $request->getUri()->withPath($location); } return $response->withStatus(302)->withHeader('Location', $location); }
/** * Retrieve custom maintenance message. * * @param WatcherInterface $watcher * * @return string */ protected function getMaintenanceMessage(WatcherInterface $watcher) { $message = 'Maintenance mode is not active!'; if ($watcher->isActive()) { $message = $watcher instanceof ScheduledWatcherInterface ? 'Undergoing maintenance tasks until ' . $watcher->getEnd()->format('Y/m/d H:i:s') : 'Undergoing maintenance tasks'; } return $message; }