1 | <?php |
||
5 | class Xhgui_Profiles |
||
6 | { |
||
7 | protected $storage; |
||
8 | |||
9 | public function __construct(\Xhgui_StorageInterface $storage) |
||
10 | { |
||
11 | $this->storage = $storage; |
||
12 | } |
||
13 | |||
14 | /** |
||
15 | * Get the latest profile data. |
||
16 | * |
||
17 | * @return Xhgui_Profile |
||
18 | * @throws Exception |
||
19 | */ |
||
20 | public function latest() |
||
21 | { |
||
22 | $cursor = $this->storage->find() |
||
|
|||
23 | ->sort(array('meta.request_date' => -1)) |
||
24 | ->limit(1); |
||
25 | $result = $cursor->getNext(); |
||
26 | return $this->_wrap($result); |
||
27 | } |
||
28 | |||
29 | public function query($conditions, $fields = null) |
||
30 | { |
||
31 | return $this->storage->find($conditions, $fields); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Get a single profile run by id. |
||
36 | * |
||
37 | * @param string $id The id of the profile to get. |
||
38 | * @return Xhgui_Profile |
||
39 | * @throws Exception |
||
40 | */ |
||
41 | public function get($id) |
||
42 | { |
||
43 | return $this->_wrap($this->storage->findOne($id)); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Get the list of profiles for a simplified url. |
||
48 | * |
||
49 | * @param string $url The url to load profiles for. |
||
50 | * @param array $options Pagination options to use. |
||
51 | * @param array $conditions The search options. |
||
52 | * @return MongoCursor |
||
53 | */ |
||
54 | public function getForUrl($url, $options, $conditions = array()) |
||
65 | |||
66 | public function paginate(Xhgui_Storage_Filter $filter) |
||
67 | { |
||
68 | $projection = false; |
||
69 | // if (isset($options['projection'])) { |
||
95 | |||
96 | /** |
||
97 | * Get the Percentile metrics for a URL |
||
98 | * |
||
99 | * This will group data by date and returns only the |
||
100 | * percentile + date, making the data ideal for time series graphs |
||
101 | * |
||
102 | * @param integer $percentile The percentile you want. e.g. 90. |
||
103 | * @param string $url |
||
104 | * @param array $search Search options containing startDate and or endDate |
||
105 | * @return array Array of metrics grouped by date |
||
106 | */ |
||
107 | public function getPercentileForUrl($percentile, $url, $filter) |
||
136 | |||
137 | /** |
||
138 | * Get a paginated set of results. |
||
139 | * |
||
140 | * @param array $options The find options to use. |
||
141 | * @return array An array of result data. |
||
142 | */ |
||
143 | public function getAll($filter) |
||
147 | |||
148 | /** |
||
149 | * Insert a profile run. |
||
150 | * |
||
151 | * Does unchecked inserts. |
||
152 | * |
||
153 | * @param array $profile The profile data to save. |
||
154 | * @return |
||
155 | */ |
||
156 | public function insert($profile) |
||
160 | |||
161 | /** |
||
162 | * Delete a profile run. |
||
163 | * |
||
164 | * @param string $id The profile id to delete. |
||
165 | * @return array|bool |
||
166 | */ |
||
167 | public function delete($id) |
||
171 | |||
172 | /** |
||
173 | * Used to truncate a collection. |
||
174 | * |
||
175 | * Primarly used in test cases to reset the test db. |
||
176 | * |
||
177 | * @return boolean |
||
178 | */ |
||
179 | public function truncate() |
||
183 | |||
184 | /** |
||
185 | * Converts arrays + MongoCursors into Xhgui_Profile instances. |
||
186 | * |
||
187 | * @param array|MongoCursor $data The data to transform. |
||
188 | * @return Xhgui_Profile|array The transformed/wrapped results. |
||
189 | * @throws Exception |
||
190 | */ |
||
191 | protected function _wrap($data) |
||
207 | } |
||
208 |
This check looks for function calls that miss required arguments.