Exemplo n.º 1
0
 /**
  * Intercept the exception and inject a response
  *
  * @param puzzle_message_ResponseInterface $response Response to set
  */
 public function intercept(puzzle_message_ResponseInterface $response)
 {
     $this->stopPropagation();
     $this->getTransaction()->setResponse($response);
     $this->exception->setThrowImmediately(false);
     puzzle_event_RequestEvents::emitComplete($this->getTransaction());
 }
Exemplo n.º 2
0
 public function testEmitsAfterSendEventAndEmitsErrorIfNeeded()
 {
     $this->_closure_testEmitsAfterSendEventAndEmitsErrorIfNeeded_ex2 = $res = null;
     $request = new puzzle_message_Request('GET', '/');
     $t = new puzzle_adapter_Transaction(new puzzle_Client(), $request);
     $t->setResponse(new puzzle_message_Response(200));
     $this->_closure_testEmitsAfterSendEventAndEmitsErrorIfNeeded_ex = new puzzle_exception_RequestException('foo', $request);
     $t->getRequest()->getEmitter()->on('complete', array($this, '__callback_testEmitsAfterSendEventAndEmitsErrorIfNeeded_1'));
     $t->getRequest()->getEmitter()->on('error', array($this, '__callback_testEmitsAfterSendEventAndEmitsErrorIfNeeded_2'));
     puzzle_event_RequestEvents::emitComplete($t);
     $this->assertSame($this->_closure_testEmitsAfterSendEventAndEmitsErrorIfNeeded_ex, $this->_closure_testEmitsAfterSendEventAndEmitsErrorIfNeeded_ex2);
 }
Exemplo n.º 3
0
 public function send(puzzle_adapter_TransactionInterface $transaction)
 {
     // HTTP/1.1 streams using the PHP stream wrapper require a
     // Connection: close header. Setting here so that it is added before
     // emitting the request.before_send event.
     $request = $transaction->getRequest();
     if ($request->getProtocolVersion() == '1.1' && !$request->hasHeader('Connection')) {
         $transaction->getRequest()->setHeader('Connection', 'close');
     }
     puzzle_event_RequestEvents::emitBefore($transaction);
     if (!$transaction->getResponse()) {
         $this->createResponse($transaction);
         puzzle_event_RequestEvents::emitComplete($transaction);
     }
     return $transaction->getResponse();
 }
Exemplo n.º 4
0
 public function send(puzzle_adapter_TransactionInterface $transaction)
 {
     puzzle_event_RequestEvents::emitBefore($transaction);
     if (!$transaction->getResponse()) {
         // Read the request body if it is present
         if ($transaction->getRequest()->getBody()) {
             $transaction->getRequest()->getBody()->__toString();
         }
         $response = is_callable($this->response) ? call_user_func($this->response, $transaction) : $this->response;
         if (!$response instanceof puzzle_message_ResponseInterface) {
             throw new RuntimeException('Invalid mocked response');
         }
         $transaction->setResponse($response);
         puzzle_event_RequestEvents::emitHeaders($transaction);
         puzzle_event_RequestEvents::emitComplete($transaction);
     }
     return $transaction->getResponse();
 }
Exemplo n.º 5
0
 public function send(puzzle_adapter_TransactionInterface $transaction)
 {
     puzzle_event_RequestEvents::emitBefore($transaction);
     if ($response = $transaction->getResponse()) {
         return $response;
     }
     $factory = $this->curlFactory;
     $handle = $factory->__invoke($transaction, $this->messageFactory, $this->checkoutEasyHandle());
     curl_exec($handle);
     $info = curl_getinfo($handle);
     $info['curl_result'] = curl_errno($handle);
     if ($info['curl_result']) {
         $this->handleError($transaction, $info, $handle);
     } else {
         $this->releaseEasyHandle($handle);
         puzzle_event_RequestEvents::emitComplete($transaction, $info);
     }
     return $transaction->getResponse();
 }
Exemplo n.º 6
0
 private function processResponse(puzzle_adapter_TransactionInterface $transaction, array $curl, puzzle_adapter_curl_BatchContext $context)
 {
     $info = $context->removeTransaction($transaction);
     try {
         if (!$this->isCurlException($transaction, $curl, $context, $info) && $this->validateResponseWasSet($transaction, $context)) {
             puzzle_event_RequestEvents::emitComplete($transaction, $info);
         }
     } catch (Exception $e) {
         $this->throwException($e, $context);
     }
 }