public function onMessage(IWebSocketConnection $connection, IWebSocketMessage $msg) { try { if ($connection->getAdminKey() == $this->getAdminKey()) { $this->dispatchAdminMessage($connection, $msg); } else { $this->dispatchMessage($connection, $msg); } } catch (Exception $e) { $this->say("Exception occurred while handling message:\r\n" . $e->getTraceAsString()); } }
public function onConnect(IWebSocketConnection $user) { if ($user->getAdminKey() == self::$ADMIN_KEY) { $this->say("[ECHO] Admin user connected"); return; } $h = $user->getHeaders(); $c = WebSocketFunctions::cookie_parse($h["Cookie"]); $client = new HttpClient($this->host); $client->cookies = $c; $client->get("/{$this->path}/?get_action=ws_authenticate&key=" . self::$ADMIN_KEY); $registry = $client->getContent(); //$this->say("[ECHO] Registry loaded".$registry); $xml = new DOMDocument(); $xml->loadXML($registry); $xPath = new DOMXPath($xml); $err = $xPath->query("//message[@type='ERROR']"); if ($err->length) { $this->say($err->item(0)->firstChild->nodeValue); $user->disconnect(); } else { $userRepositories = array(); $repos = $xPath->query("/tree/user/repositories/repo"); foreach ($repos as $repo) { $repoId = $repo->attributes->getNamedItem("id")->nodeValue; $userRepositories[] = $repoId; } $user->ajxpRepositories = $userRepositories; $user->ajxpId = $xPath->query("/tree/user/@id")->item(0)->nodeValue; if ($xPath->query("/tree/user/@groupPath")->length) { $groupPath = $xPath->query("/tree/user/@groupPath")->item(0)->nodeValue; if (!empty($groupPath)) { $user->ajxpGroupPath = $groupPath; } } } $this->say("[ECHO] User '" . $user->ajxpId . "' connected with " . count($user->ajxpRepositories) . " registered repositories "); }