scratch – Blame information for rev 87
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
87 | office | 1 | <?php |
2 | |||
3 | namespace GuzzleHttp\Event; |
||
4 | |||
5 | use GuzzleHttp\Adapter\TransactionInterface; |
||
6 | use GuzzleHttp\Message\ResponseInterface; |
||
7 | |||
8 | /** |
||
9 | * Event that contains transaction statistics (time over the wire, lookup time, |
||
10 | * etc.). |
||
11 | * |
||
12 | * Adapters that create this event SHOULD add, at a minimum, the 'total_time' |
||
13 | * transfer statistic that measures the amount of time, in seconds, taken to |
||
14 | * complete a transfer for the current request/response cycle. Each event |
||
15 | * pertains to a single request/response transaction, NOT the entire |
||
16 | * transaction (e.g. redirects). |
||
17 | * |
||
18 | * Adapters that add transaction statistics SHOULD follow the same string |
||
19 | * attribute names that are provided by cURL listed at |
||
20 | * http://php.net/manual/en/function.curl-getinfo.php. However, not all |
||
21 | * adapters will have access to the advanced statistics provided by cURL. The |
||
22 | * most useful transfer statistics are as follows: |
||
23 | * |
||
24 | * - total_time: Total transaction time in seconds for last transfer |
||
25 | * - namelookup_time: Time in seconds until name resolving was complete |
||
26 | * - connect_time: Time in seconds it took to establish the connection |
||
27 | * - pretransfer_time: Time in seconds from start until just before file |
||
28 | * transfer begins. |
||
29 | * - starttransfer_time: Time in seconds until the first byte is about to be |
||
30 | * transferred. |
||
31 | * - speed_download: Average download speed, measured in bytes/second. |
||
32 | * - speed_upload: Average upload speed, measured in bytes/second. |
||
33 | */ |
||
34 | abstract class AbstractTransferEvent extends AbstractRequestEvent |
||
35 | { |
||
36 | private $transferInfo; |
||
37 | |||
38 | /** |
||
39 | * @param TransactionInterface $transaction Transaction |
||
40 | * @param array $transferInfo Transfer statistics |
||
41 | */ |
||
42 | public function __construct( |
||
43 | TransactionInterface $transaction, |
||
44 | $transferInfo = [] |
||
45 | ) { |
||
46 | parent::__construct($transaction); |
||
47 | $this->transferInfo = $transferInfo; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Get all transfer information as an associative array if no $name |
||
52 | * argument is supplied, or gets a specific transfer statistic if |
||
53 | * a $name attribute is supplied (e.g., 'total_time'). |
||
54 | * |
||
55 | * @param string $name Name of the transfer stat to retrieve |
||
56 | * |
||
57 | * @return mixed|null|array |
||
58 | */ |
||
59 | public function getTransferInfo($name = null) |
||
60 | { |
||
61 | if (!$name) { |
||
62 | return $this->transferInfo; |
||
63 | } |
||
64 | |||
65 | return isset($this->transferInfo[$name]) |
||
66 | ? $this->transferInfo[$name] |
||
67 | : null; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Get the response |
||
72 | * |
||
73 | * @return ResponseInterface|null |
||
74 | */ |
||
75 | abstract public function getResponse(); |
||
76 | |||
77 | /** |
||
78 | * Intercept the request and associate a response |
||
79 | * |
||
80 | * @param ResponseInterface $response Response to set |
||
81 | */ |
||
82 | abstract public function intercept(ResponseInterface $response); |
||
83 | } |