composer package updates
[openemr.git] / vendor / doctrine / couchdb / lib / Doctrine / CouchDB / HTTP / LoggingClient.php
blobb9f4ce10e5f188e1e0de15be41ab8ca9f2ccc6c1
1 <?php
2 /*
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\CouchDB\HTTP;
22 class LoggingClient implements Client
24 /**
25 * @var Client
27 private $client;
29 /**
30 * Array of requests made to CouchDB with this client.
32 * Contains the following keys:
33 * - duration - Microseconds it took to execute and process the request
34 * - method (GET, POST, ..)
35 * - path - The requested url path on the server including parameters
36 * - request - The request body if its size is smaller than 10000 chars.
37 * - request_size - The size of the request body
38 * - response_status - The response HTTP status
39 * - response - The body of the response.
40 * - response_headers
42 * @var array
44 public $requests = array();
46 /**
47 * @var float
49 public $totalDuration = 0;
51 /**
52 * Construct new logging client wrapping the real client.
54 * @param Client $client
56 public function __construct(Client $client)
58 $this->client = $client;
61 public function request($method, $path, $data = null, $raw = false, array $headers = array())
63 $start = microtime(true);
65 $response = $this->client->request($method, $path, $data, $raw, $headers);
67 $duration = microtime(true) - $start;
68 $this->requests[] = array(
69 'duration' => $duration,
70 'method' => $method,
71 'path' => rawurldecode($path),
72 'request' => $data,
73 'request_size' => strlen($data),
74 'response_status' => $response->status,
75 'response' => $response->body,
76 'response_headers' => $response->headers,
78 $this->totalDuration += $duration;
80 return $response;
83 public function getConnection(
84 $method,
85 $path,
86 $data = null,
87 array $headers = array()
88 ) {
89 $start = microtime(true);
91 $response = $this->client->getConnection(
92 $method,
93 $path,
94 $data,
95 $headers
98 $duration = microtime(true) - $start;
99 $this->requests[] = array(
100 'duration' => $duration,
101 'method' => $method,
102 'path' => rawurldecode($path),
103 'request' => $data,
104 'request_size' => strlen($data),
105 'response_status' => $response->status,
106 'response' => $response->body,
107 'response_headers' => $response->headers,
109 $this->totalDuration += $duration;
111 return $response;