uriIsValid() public static method

Strict URI Test
public static uriIsValid ( $uri ) : boolean
$uri
return boolean
示例#1
0
 /**
  * @param $uri
  * @param $options
  * @return bool
  */
 public function uriIsValid($uri, $options)
 {
     $uri = $this->fixupUri($uri);
     // if the uri is empty - then match everything
     if ($uri == "") {
         return true;
     }
     // if there is a trailing . then remove it and run it through the
     // regular validator
     $uri = substr($uri, strlen($uri) - 1) == "." ? substr($uri, 0, strlen($uri) - 1) : $uri;
     // allow matches to a normal URI or one with a trailing dot
     return Utils::uriIsValid($uri) || Utils::uriIsValid($uri . ".");
 }
示例#2
0
 /**
  * @param $uri
  * @param $options
  * @return bool
  */
 public function uriIsValid($uri, $options)
 {
     return Utils::uriIsValid($uri);
 }
示例#3
0
 /**
  * Process call
  *
  * @param \Thruway\Session $session
  * @param \Thruway\Message\CallMessage $msg
  * @return boolean
  */
 private function processCall(Session $session, CallMessage $msg)
 {
     if (!Utils::uriIsValid($msg->getProcedureName())) {
         $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.invalid_uri'));
         return;
     }
     if (!isset($this->procedures[$msg->getProcedureName()])) {
         $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_procedure'));
         return;
     }
     /* @var $procedure \Thruway\Procedure */
     $procedure = $this->procedures[$msg->getProcedureName()];
     $call = new Call($session, $msg, $procedure);
     $this->callInvocationIndex[$call->getInvocationRequestId()] = $call;
     $this->callRequestIndex[$msg->getRequestId()] = $call;
     $keepIndex = $procedure->processCall($session, $call);
     if (!$keepIndex) {
         $this->removeCall($call);
     }
 }
示例#4
0
 /**
  * @param string $handlerUri
  * @throws \Exception
  */
 public function setStateHandler($handlerUri)
 {
     if (!Utils::uriIsValid($handlerUri)) {
         Logger::error($this, "Invalid URI");
         throw new \InvalidArgumentException("Invalid URI");
     }
     $this->stateHandler = $handlerUri;
 }
示例#5
0
 /**
  * Arguments need to be [["role1", "role2"], "publish|subscribe|register|call", "my.uri"]
  *
  * @param $args
  * @return bool|mixed
  */
 public function testAuthorization($args)
 {
     if (is_array($args) && count($args) < 3) {
         return false;
     }
     $roles = $args[0];
     if (is_string($roles)) {
         $roles = [$roles];
     }
     $action = $args[1];
     if (!static::isValidAction($action)) {
         return false;
     }
     $uriToCheck = $args[2];
     if (!Utils::uriIsValid($uriToCheck)) {
         return false;
     }
     return $this->isAuthorizedByRolesActionAndUri($roles, $action, $uriToCheck);
 }
示例#6
0
 private function handleCallHttpRequest($request, $response)
 {
     $bodySnatcher = new BodySnatcher($request);
     $bodySnatcher->promise()->then(function ($body) use($request, $response) {
         try {
             //{"procedure": "com.myapp.procedure1", "args": ["Hello, world"], "argsKw": {}, "options": {} }
             $json = json_decode($body);
             if (isset($json->procedure) && Utils::uriIsValid($json->procedure) && $this->getCaller() !== null) {
                 $args = isset($json->args) && is_array($json->args) ? $json->args : null;
                 $argsKw = isset($json->argsKw) && is_object($json->argsKw) ? $json->argsKw : null;
                 $options = isset($json->options) && is_object($json->options) ? $json->options : null;
                 $this->getSession()->call($json->procedure, $args, $argsKw, $options)->then(function (CallResult $result) use($response) {
                     $responseObj = new \stdClass();
                     $responseObj->result = "SUCCESS";
                     $responseObj->args = $result->getArguments();
                     $responseObj->argsKw = $result->getArgumentsKw();
                     $responseObj->details = $result->getDetails();
                     $response->writeHead(200, ['Content-Type' => 'application/json', 'Connection' => 'close']);
                     $response->end(json_encode($responseObj));
                 }, function (ErrorMessage $msg) use($response) {
                     $responseObj = new \stdClass();
                     $responseObj->result = "ERROR";
                     $responseObj->error_uri = $msg->getErrorURI();
                     $responseObj->error_args = $msg->getArguments();
                     $responseObj->error_argskw = $msg->getArgumentsKw();
                     $responseObj->error_details = $msg->getDetails();
                     // maybe return an error code here
                     $response->writeHead(200, ['Content-Type' => 'application/json', 'Connection' => 'close']);
                     $response->end(json_encode($responseObj));
                 });
             } else {
                 // maybe return an error code here
                 $response->writeHead(200, ['Content-Type' => 'text/plain', 'Connection' => 'close']);
                 $response->end("No procedure set");
             }
         } catch (\Exception $e) {
             // maybe return an error code here
             $response->writeHead(200, ['Content-Type' => 'text/plain', 'Connection' => 'close']);
             $response->end("Problem");
         }
     });
 }