scratch – Blame information for rev 87

Subversion Repositories:
Rev:
Rev Author Line No. Line
87 office 1 <?php
2  
3 namespace GuzzleHttp\Event;
4  
5 use GuzzleHttp\Adapter\TransactionInterface;
6 use GuzzleHttp\Exception\RequestException;
7 use GuzzleHttp\Message\ResponseInterface;
8  
9 /**
10 * Event object emitted after a request has been sent and an error was
11 * encountered.
12 *
13 * You may intercept the exception and inject a response into the event to
14 * rescue the request.
15 */
16 class ErrorEvent extends AbstractTransferEvent
17 {
18 private $exception;
19  
20 /**
21 * @param TransactionInterface $transaction Transaction that contains the request
22 * @param RequestException $e Exception encountered
23 * @param array $transferStats Array of transfer statistics
24 */
25 public function __construct(
26 TransactionInterface $transaction,
27 RequestException $e,
28 $transferStats = []
29 ) {
30 parent::__construct($transaction, $transferStats);
31 $this->exception = $e;
32 }
33  
34 /**
35 * Intercept the exception and inject a response
36 *
37 * @param ResponseInterface $response Response to set
38 */
39 public function intercept(ResponseInterface $response)
40 {
41 $this->stopPropagation();
42 $this->getTransaction()->setResponse($response);
43 $this->exception->setThrowImmediately(false);
44 RequestEvents::emitComplete($this->getTransaction());
45 }
46  
47 /**
48 * Get the exception that was encountered
49 *
50 * @return RequestException
51 */
52 public function getException()
53 {
54 return $this->exception;
55 }
56  
57 /**
58 * Get the response the was received (if any)
59 *
60 * @return ResponseInterface|null
61 */
62 public function getResponse()
63 {
64 return $this->getException()->getResponse();
65 }
66  
67 /**
68 * Request that a ParallelAdapterInterface throw the associated exception
69 * if the exception is unhandled.
70 *
71 * If the error event was not emitted from a ParallelAdapterInterface, then
72 * the effect of this method is nil.
73 *
74 * @param bool $throwImmediately Whether or not to throw immediately
75 */
76 public function throwImmediately($throwImmediately)
77 {
78 $this->exception->setThrowImmediately($throwImmediately);
79 }
80 }