Exemplo n.º 1
0
 /**
  * Offers a generic and reusable method to handle exceptions generated by
  * a connection object.
  *
  * @deprecated Deprecated since v0.8.3 - moved in Predis\CommunicationException::handle()
  * @param CommunicationException $exception Exception.
  */
 public static function onCommunicationException(CommunicationException $exception)
 {
     if ($exception->shouldResetConnection()) {
         $connection = $exception->getConnection();
         if ($connection->isConnected()) {
             $connection->disconnect();
         }
     }
     throw $exception;
 }
Exemplo n.º 2
0
 public function __construct($httpResponseBody)
 {
     parent::__construct('Input Validation Failed', static::INVALID_INPUT);
     $this->httpResponseBody = $httpResponseBody;
     $errors = json_decode($httpResponseBody, true);
     if (is_array($errors) && array_key_exists('errors', $errors)) {
         $this->errors = $errors['errors'];
     }
 }
Exemplo n.º 3
0
 /**
  * Execute a request to the FastCGI application asynchronously
  * This sends request to application and returns the assigned ID for that request.
  * You should keep this id for later use with wait_for_response(). Ids are chosen randomly
  * rather than sequentially to guard against false-positives when using persistent sockets.
  * In that case it is possible that a delayed response to a request made by a previous script
  * invocation comes back on this socket and is mistaken for response to request made with same ID
  * during this request.
  *
  * @param array  $params Array of parameters
  * @param String $stdin  Content
  * @return Response
  * @throws CommunicationException
  */
 public function asyncRequest(array $params, $stdin)
 {
     $this->connect();
     // Ensure new requestID is not already being tracked
     do {
         $this->_requestCounter++;
         if ($this->_requestCounter >= 65536) {
             $this->_requestCounter = 1;
         }
         $id = $this->_requestCounter;
     } while (isset($this->_requests[$id]));
     $request = $this->buildPacket(self::BEGIN_REQUEST, chr(0) . chr(self::RESPONDER) . chr((int) $this->keepAlive) . str_repeat(chr(0), 5), $id);
     $paramsRequest = '';
     foreach ($params as $key => $value) {
         $paramsRequest .= $this->buildNvpair($key, $value, $id);
     }
     if ($paramsRequest) {
         $request .= $this->buildPacket(self::PARAMS, $paramsRequest, $id);
     }
     $request .= $this->buildPacket(self::PARAMS, '', $id);
     if ($stdin) {
         $request .= $this->buildPacket(self::STDIN, $stdin, $id);
     }
     $request .= $this->buildPacket(self::STDIN, '', $id);
     if (false === socket_write($this->sock, $request)) {
         // The developer may wish to close() and re-open the socket
         throw CommunicationException::socketWrite($this->sock);
     }
     $req = new Response($this, $id);
     $req->state = Response::REQ_STATE_WRITTEN;
     $this->_requests[$id] = $req;
     return $req;
 }
Exemplo n.º 4
0
 /**
  * Execute a request to the FastCGI application
  *
  * @param array $params Array of parameters
  * @param String $stdin Content
  * @throws CommunicationException
  */
 protected function doRequest(array $params, $stdin)
 {
     $this->connect();
     $request = $this->buildPacket(self::BEGIN_REQUEST, chr(0) . chr(self::RESPONDER) . chr((int) $this->keepAlive) . str_repeat(chr(0), 5));
     $paramsRequest = '';
     foreach ($params as $key => $value) {
         $paramsRequest .= $this->buildNvpair($key, $value);
     }
     if ($paramsRequest) {
         $request .= $this->buildPacket(self::PARAMS, $paramsRequest);
     }
     $request .= $this->buildPacket(self::PARAMS, '');
     if ($stdin) {
         $request .= $this->buildPacket(self::STDIN, $stdin);
     }
     $request .= $this->buildPacket(self::STDIN, '');
     // Write the request and break.
     if (false === @socket_write($this->sock, $request)) {
         throw CommunicationException::socketWrite($this->sock);
     }
     $this->awaitingResponse = true;
 }
Exemplo n.º 5
0
 public function __construct($message = null, $code = 0)
 {
     if (empty($message)) {
         $message = __('Facebook returned an unexpected dataset.', FPP_TEXT_DOMAIN) . ' ' . __('Try to resolve this issue, update the plugin or <a target="_blank" href="http://wordpress.org/tags/facebook-page-publish">inform the author</a> about the problem.', FPP_TEXT_DOMAIN);
     } else {
         $message = sprintf(__('Facebook returned an unexpected dataset: %s', FPP_TEXT_DOMAIN), $message) . '<br />' . __('Try to resolve this issue, update the plugin or <a target="_blank" href="http://wordpress.org/tags/facebook-page-publish">inform the author</a> about the problem.', FPP_TEXT_DOMAIN);
     }
     parent::__construct($message, $code);
 }