1 | <?php |
||
15 | class Kohana_Report_GoogleAnalytics extends Report |
||
16 | { |
||
17 | const URL = 'https://www.googleapis.com/analytics/v3/data/ga'; |
||
18 | |||
19 | protected $_metrics; |
||
20 | protected $_sort; |
||
21 | protected $_max_results; |
||
22 | protected $_dimensions; |
||
23 | protected $_project_id; |
||
24 | protected $_access_token; |
||
25 | protected $_filters; |
||
26 | protected $_segment; |
||
27 | protected $_start_index; |
||
28 | protected $_date_template = 'Y-m-d'; |
||
29 | |||
30 | /** |
||
31 | * Build all the request query parameters needed to access the google analytics API |
||
32 | * @return array |
||
33 | */ |
||
34 | public function request_params() |
||
51 | |||
52 | /** |
||
53 | * Return the project_id set in the config or set it for this report |
||
54 | * @return string|$this |
||
55 | */ |
||
56 | public function project_id($project_id = NULL) |
||
70 | |||
71 | /** |
||
72 | * Generate a new access token for google analytics API using client_id, client_secret and refresh_token, set in the config |
||
73 | * @return string |
||
74 | */ |
||
75 | public function access_token() |
||
105 | |||
106 | /** |
||
107 | * Get the result from calling Google Anlaytics API |
||
108 | * @return array |
||
109 | */ |
||
110 | public function retrieve() |
||
114 | |||
115 | /** |
||
116 | * Rows from Google Analytics API response |
||
117 | * @return array |
||
118 | */ |
||
119 | public function rows() |
||
123 | |||
124 | /** |
||
125 | * Get 'totals' from Google Analytics API response |
||
126 | * @return mixed |
||
127 | */ |
||
128 | public function total() |
||
132 | |||
133 | /** |
||
134 | * Getter / Setter |
||
135 | * The maximum number of rows to include in the response. |
||
136 | * |
||
137 | * @link https://developers.google.com/analytics/devguides/reporting/core/v3/reference#maxResults |
||
138 | * @param int $max_results |
||
139 | * @return int|$this |
||
140 | */ |
||
141 | public function max_results($max_results = NULL) |
||
150 | |||
151 | /** |
||
152 | * Getter / Setter |
||
153 | * A list of comma-separated dimensions for your Analytics data, such as ga:browser,ga:city. |
||
154 | * |
||
155 | * @link https://developers.google.com/analytics/devguides/reporting/core/v3/reference#dimensions |
||
156 | * @param string $dimensions |
||
157 | * @return string|$this |
||
158 | */ |
||
159 | public function dimensions($dimensions = NULL) |
||
168 | |||
169 | /** |
||
170 | * Getter / Setter |
||
171 | * A list of comma-separated metrics, such as ga:visits,ga:bounces. |
||
172 | * |
||
173 | * @link https://developers.google.com/analytics/devguides/reporting/core/v3/reference#metrics |
||
174 | * @param string $metrics |
||
175 | * @return string|$this |
||
176 | */ |
||
177 | public function metrics($metrics = NULL) |
||
186 | |||
187 | /** |
||
188 | * Getter / Setter |
||
189 | * A list of comma-separated dimensions and metrics indicating the sorting order and sorting direction for the returned data. |
||
190 | * |
||
191 | * @link https://developers.google.com/analytics/devguides/reporting/core/v3/reference#sort |
||
192 | * @param string $sort |
||
193 | * @return string|$this |
||
194 | */ |
||
195 | public function sort($sort = NULL) |
||
204 | |||
205 | /** |
||
206 | * Getter / Setter |
||
207 | * Dimension or metric filters that restrict the data returned for your request. |
||
208 | * |
||
209 | * @link https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters |
||
210 | * @param string $filters |
||
211 | * @return string|$this |
||
212 | */ |
||
213 | public function filters($filters = NULL) |
||
222 | |||
223 | /** |
||
224 | * Getter / Setter |
||
225 | * Segments the data returned for your request. |
||
226 | * |
||
227 | * @link https://developers.google.com/analytics/devguides/reporting/core/v3/reference#segment |
||
228 | * @param string $segment |
||
229 | * @return string|$this |
||
230 | */ |
||
231 | public function segment($segment = NULL) |
||
240 | |||
241 | /** |
||
242 | * Getter / Setter |
||
243 | * The first row of data to retrieve, starting at 1. Use this parameter as a pagination mechanism along with the max-results parameter. |
||
244 | * |
||
245 | * @link https://developers.google.com/analytics/devguides/reporting/core/v3/reference#startIndex |
||
246 | * @param string $start_index |
||
247 | * @return string|$this |
||
248 | */ |
||
249 | public function start_index($start_index = NULL) |
||
258 | } |
||
259 | |||
260 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: