Beispiel #1
0
 /**
  * @group utils
  */
 public function testEndsWith()
 {
     $this->assertTrue(\Pubnub\PubnubUtil::string_ends_with("foo-pnpres", "-pnpres"));
     $this->assertTrue(\Pubnub\PubnubUtil::string_ends_with("foo.bar-pnpres", "-pnpres"));
     $this->assertTrue(\Pubnub\PubnubUtil::string_ends_with("foo.*-pnpres", "-pnpres"));
     $this->assertFalse(\Pubnub\PubnubUtil::string_ends_with("foo", "-pnpres"));
     $this->assertFalse(\Pubnub\PubnubUtil::string_ends_with("foo.bar", "-pnpres"));
 }
Beispiel #2
0
 private function execute()
 {
     $chs = $this->chs();
     $ch = $chs[0];
     $output = curl_exec($ch);
     $curlError = curl_errno($ch);
     $curlResponseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $curlResponseURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
     $JSONDecodedResponse = PubnubUtil::json_decode($output);
     curl_close($ch);
     $this->requests = array();
     if ($JSONDecodedResponse != null) {
         return $JSONDecodedResponse;
     } elseif ($curlError == 28) {
         throw new PubnubException("Pubnub request timeout. Maximum timeout: " . $this->curlTimeout . " seconds" . ". Requested URL: " . $curlResponseURL);
     } else {
         throw new PubnubException("Empty response from Pubnub. HTTP code: " . $curlResponseCode . ". cURL error code: " . $curlError . ". Requested URL: " . $curlResponseURL);
     }
 }
Beispiel #3
0
 private function execute()
 {
     $chs = $this->chs();
     $ch = $chs[0];
     $output = curl_exec($ch);
     $curlError = curl_errno($ch);
     $curlResponseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $curlResponseURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
     $JSONDecodedResponse = PubnubUtil::json_decode($output);
     curl_close($ch);
     $this->requests = array();
     if ($JSONDecodedResponse != null) {
         return $JSONDecodedResponse;
     } elseif ($curlError == 28) {
         return array('error' => true, 'service' => 'cURL', 'status' => -1, 'message' => 'request timeout', 'payload' => "Pubnub request timeout. Maximum timeout: " . $this->curlSubscribeTimeout . " second(s) for subscribe and " . $this->curlTimeout . " second(s) for non-subscribe requests. " . "Requested URL: " . $curlResponseURL);
     } else {
         throw new PubnubException("Empty response from Pubnub. HTTP code: " . $curlResponseCode . ". cURL error code: " . $curlError . ". Requested URL: " . $curlResponseURL);
     }
 }
Beispiel #4
0
 /**
  * Check if wc message should be passed to user callback
  *
  * @param string $channel
  * @param string $group
  * @param array $subscribe
  * @param array $presence
  * @param PubnubLogger $logger
  * @return bool passed if message should be passed to user callback
  */
 public static function shouldWildcardMessageBePassedToUserCallback($channel, $group, $subscribe, $presence, $logger)
 {
     // if presence message while only subscribe
     if (PubnubUtil::string_ends_with($channel, static::PRESENCE_SUFFIX) && !in_array($group, $presence)) {
         $logger->debug("WC presence message on " . $channel . " while is not subscribe for presence");
         return false;
         // if subscribe message while only presence
     } elseif (!PubnubUtil::string_ends_with($channel, static::PRESENCE_SUFFIX) && !in_array($group, $subscribe)) {
         $logger->debug("WC subscribe message on " . $channel . " while is not subscribe for messages");
         return false;
     } else {
         return true;
     }
 }