1 | <?php |
||
20 | class HttpClient |
||
21 | { |
||
22 | /** |
||
23 | * User agent for the client. |
||
24 | */ |
||
25 | const PHP_GA_MEASUREMENT_PROTOCOL_USER_AGENT = |
||
26 | 'THE ICONIC GA Measurement Protocol PHP Client (https://github.com/theiconic/php-ga-measurement-protocol)'; |
||
27 | |||
28 | /** |
||
29 | * Timeout in seconds for the request connection and actual request execution. |
||
30 | * Using the same value you can find in Google's PHP Client. |
||
31 | */ |
||
32 | const REQUEST_TIMEOUT_SECONDS = 100; |
||
33 | |||
34 | /** |
||
35 | * HTTP client. |
||
36 | * |
||
37 | * @var Client |
||
38 | */ |
||
39 | private $client; |
||
40 | |||
41 | /** |
||
42 | * Holds the promises (async responses). |
||
43 | * |
||
44 | * @var PromiseInterface[] |
||
45 | */ |
||
46 | private static $promises = []; |
||
47 | |||
48 | /** |
||
49 | * We have to unwrap and send all promises at the end before analytics objects is destroyed. |
||
50 | */ |
||
51 | public function __destruct() |
||
55 | |||
56 | /** |
||
57 | * Sets HTTP client. |
||
58 | * |
||
59 | * @param Client $client |
||
60 | */ |
||
61 | public function setClient(Client $client) |
||
65 | |||
66 | /** |
||
67 | * Gets HTTP client for internal class use. |
||
68 | * |
||
69 | * @return Client |
||
70 | */ |
||
71 | private function getClient() |
||
81 | |||
82 | /** |
||
83 | * Sends request to Google Analytics. |
||
84 | * |
||
85 | * @param string $url |
||
86 | * @param boolean $nonBlocking |
||
87 | * @return AnalyticsResponse |
||
88 | */ |
||
89 | public function post($url, $nonBlocking = false) |
||
111 | |||
112 | /** |
||
113 | * Creates an analytics response object. |
||
114 | * |
||
115 | * @param RequestInterface $request |
||
116 | * @param ResponseInterface|PromiseInterface $response |
||
117 | * @return AnalyticsResponse |
||
118 | */ |
||
119 | protected function getAnalyticsResponse(RequestInterface $request, $response) |
||
123 | } |
||
124 |