/**
  * Parses response body as JSON
  * Result is cached internally
  * @param bool $asObject
  * @return stdClass|array
  * @throws Exception
  */
 public function getJson($asObject = true)
 {
     if (!$this->isContentType('application/json')) {
         throw new Exception('Response is not JSON');
     }
     if ($asObject && empty($this->jsonAsObject) || !$asObject && empty($this->jsonAsArray)) {
         $json = Utils::json_parse((string) $this->response->getBody(), !$asObject);
         if ($asObject) {
             $this->jsonAsObject = $json;
         } else {
             $this->jsonAsArray = $json;
         }
     }
     return $asObject ? $this->jsonAsObject : $this->jsonAsArray;
 }
 protected function decrypt($message)
 {
     if (!$this->subscribed()) {
         throw new Exception('No subscription');
     }
     if ($this->_subscription['deliveryMode']['encryption'] && $this->_subscription['deliveryMode']['encryptionKey']) {
         $aes = new PubnubAES();
         $message = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, base64_decode($this->_subscription['deliveryMode']['encryptionKey']), base64_decode($message), MCRYPT_MODE_ECB);
         $message = Utils::json_parse($aes->unPadPKCS7($message, 128), true);
         // PUBNUB itself always decode as array
     }
     return $message;
 }
 /**
  * @inheritdoc
  */
 public function getResponse(RequestInterface $request)
 {
     $body = Utils::json_parse((string) $request->getBody(), true);
     return self::createBody(array('eventFilters' => $body['eventFilters'], 'expirationTime' => date('c', time() + $this->expiresIn), 'expiresIn' => $this->expiresIn, 'deliveryMode' => array('transportType' => 'PubNub', 'encryption' => false, 'address' => '123_foo', 'subscriberKey' => 'sub-c-foo', 'secretKey' => 'sec-c-bar'), 'id' => 'foo-bar-baz', 'creationTime' => date('c'), 'status' => 'Active', 'uri' => 'https=>//platform.ringcentral.com/restapi/v1.0/subscription/foo-bar-baz'));
 }
示例#4
0
 /**
  * Test padded AES result
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage JSON Error: Unexpected control character found
  */
 public function testControl()
 {
     Utils::json_parse("{\"foo\":\"bar\"}");
 }
 /**
  * Parses response body as JSON and returns an array
  * Result is cached internally
  * @return array
  * @throws Exception
  */
 public function jsonArray()
 {
     if (!$this->isContentType('application/json')) {
         throw new Exception('Response is not JSON');
     }
     if (empty($this->_jsonAsArray)) {
         $this->_jsonAsArray = Utils::json_parse($this->text(), true);
     }
     return $this->_jsonAsArray;
 }
示例#6
0
 /**
  * Attention, this function is NOT PUBLIC!!! The only reason it's public is due to PHP 5.3 limitations
  * @protected
  * @param $pubnubMessage
  * @return bool
  * @throws Exception
  */
 public function notify($pubnubMessage)
 {
     $message = $pubnubMessage['message'];
     //TODO Since pubnub blocks everything this is probably the only place where we can intercept the process and do subscription renew
     //$this->renew();
     if (!$this->alive()) {
         throw new Exception('Subscription is not alive');
     }
     if ($this->_subscription['deliveryMode']['encryption'] && $this->_subscription['deliveryMode']['encryptionKey']) {
         $aes = new PubnubAES();
         $message = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, base64_decode($this->_subscription['deliveryMode']['encryptionKey']), base64_decode($message), MCRYPT_MODE_ECB);
         $message = Utils::json_parse($aes->unPadPKCS7($message, 128), true);
         // PUBNUB itself always decode as array
     }
     //print 'Message received: ' . $message . PHP_EOL;
     $this->dispatch(self::EVENT_NOTIFICATION, new NotificationEvent($message));
     return $this->_keepPolling;
 }