getUri()->getPath(); if ($path === "/index.html") { $resolve(Response::html(self::$indexPage)); } switch (true) { case preg_match('<^/.well-known/mercure/subscriptions(/.+?)$>', $path, $m): $query = explode("/", trim($m[1]??null, "/")); $topic = array_shift($query); $subscription = array_shift($query); $resolve($this->apiGetSubscriptions($topic, $subscription)); return; case preg_match('<^/.well-known/mercureact/status$>', $path): $resolve([ 'server' => 'Mercureact/1.0', 'topics' => $this->topicManager->getTopicCount(), 'subscriptions' => $this->topicManager->getSubscriberCount(), 'memoryPeak' => memory_get_peak_usage(true), 'memoryUsage' => memory_get_usage(true) ]); return; case preg_match('<^/.well-known/mercureact/status$>', $path): $resolve([ 'version' => '1.0' ]); return; } $resolve($next($request)); } ); } /** * * * @return ResponseInterface */ private function apiGetSubscriptions(string|null $topic, string|null $subscription): ResponseInterface { // TODO implement once we can enumerate topics and subscriptions // mock data $lastEventId = "urn:uuid:5e94c686-2c0b-4f9b-958c-92ccc3bbb4eb"; $data = [ "@context" => "https://mercure.rocks/", "id" => "/.well-known/mercure/subscriptions", "type" => "Subscriptions", "lastEventID" => $lastEventId, "subscriptions" => [] ]; return Response::json($data) ->withHeader('Content-Type', 'application/ld+json') ->withHeader('ETag', $lastEventId); } } ApiHandler::$indexPage = << ENDHTML;