Thruway\RealmManager::getRealm PHP Method

getRealm() public method

Get Realm by realm name
public getRealm ( string $realmName ) : Realm
$realmName string
return Realm
    public function getRealm($realmName)
    {
        if (!is_scalar($realmName)) {
            throw new \InvalidArgumentException("Non-string value given for realm name");
        }
        if (!array_key_exists($realmName, $this->realms)) {
            if ($this->getAllowRealmAutocreate()) {
                Logger::debug($this, "Creating new realm \"" . $realmName . "\"");
                $realm = new Realm($realmName);
                $this->addRealm($realm);
            } else {
                throw new RealmNotFoundException();
            }
        }
        return $this->realms[$realmName];
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Handle transport recived message
  *
  * @param \Thruway\Transport\TransportInterface $transport
  * @param \Thruway\Message\Message $msg
  * @return void
  */
 public function onMessage(TransportInterface $transport, Message $msg)
 {
     /* @var $session \Thruway\Session */
     $session = $this->sessions[$transport];
     // see if the session is in a realm
     if ($session->getRealm() === null) {
         if ($msg instanceof AbortMessage) {
             $session->shutdown();
             return;
         }
         // hopefully this is a HelloMessage or we have no place for this message to go
         if ($msg instanceof HelloMessage) {
             try {
                 $realm = $this->realmManager->getRealm($msg->getRealm());
                 $realm->onMessage($session, $msg);
             } catch (\Exception $e) {
                 // TODO: Test this
                 $errorUri = "wamp.error.unknown";
                 $description = $e->getMessage();
                 if ($e instanceof InvalidRealmNameException || $e instanceof RealmNotFoundException) {
                     $errorUri = "wamp.error.no_such_realm";
                 }
                 $session->abort(['description' => $description], $errorUri);
             }
         } else {
             $session->abort(new \stdClass(), "wamp.error.unknown");
         }
     } else {
         $realm = $session->getRealm();
         $realm->onMessage($session, $msg);
     }
 }
All Usage Examples Of Thruway\RealmManager::getRealm