This repository was archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathOptions.php
More file actions
442 lines (399 loc) · 11.3 KB
/
Copy pathOptions.php
File metadata and controls
442 lines (399 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<?php
/**
* Zend Developer Tools for Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendDeveloperTools for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace ZendDeveloperTools;
use Zend\Stdlib\AbstractOptions;
class Options extends AbstractOptions
{
/**
* @var ReportInterface
*/
protected $report;
/**
* @var array
*/
protected $profiler = array(
'enabled' => false,
'strict' => true,
'flush_early' => false,
'cache_dir' => 'data/cache',
'matcher' => array(),
'collectors' => array(
'db' => 'ZendDeveloperTools\DbCollector',
'exception' => 'ZendDeveloperTools\ExceptionCollector',
'request' => 'ZendDeveloperTools\RequestCollector',
'config' => 'ZendDeveloperTools\ConfigCollector',
'memory' => 'ZendDeveloperTools\MemoryCollector',
'time' => 'ZendDeveloperTools\TimeCollector',
),
);
/**
* Defaults for event-level logging
* @var array
*/
protected $events = array(
'enabled' => false,
'collectors' => array(
'memory' => 'ZendDeveloperTools\MemoryCollector',
'time' => 'ZendDeveloperTools\TimeCollector',
),
'identifiers' => array(
'all' => '*'
)
);
/**
* @var array
*/
protected $toolbar = array(
'enabled' => false,
'auto_hide' => false,
'position' => 'bottom',
'version_check' => false,
'entries' => array(
'request' => 'zend-developer-tools/toolbar/request',
'time' => 'zend-developer-tools/toolbar/time',
'memory' => 'zend-developer-tools/toolbar/memory',
'config' => 'zend-developer-tools/toolbar/config',
'db' => 'zend-developer-tools/toolbar/db',
),
);
/**
* @var array
*/
protected $backgroundrequests = array(
'enabled' => false,
);
/**
* Overloading Constructor.
*
* @param array|Traversable|null $options
* @param ReportInterface $report
* @throws \Zend\Stdlib\Exception\InvalidArgumentException
*/
public function __construct($options, ReportInterface $report)
{
$this->report = $report;
parent::__construct($options);
}
/**
* Sets Profiler options.
*
* @param array $options
*/
public function setProfiler(array $options)
{
if (isset($options['enabled'])) {
$this->profiler['enabled'] = (bool) $options['enabled'];
}
if (isset($options['strict'])) {
$this->profiler['strict'] = (bool) $options['strict'];
}
if (isset($options['flush_early'])) {
$this->profiler['flush_early'] = (bool) $options['flush_early'];
}
if (isset($options['cache_dir'])) {
$this->profiler['cache_dir'] = (string) $options['cache_dir'];
}
if (isset($options['matcher'])) {
$this->setMatcher($options['matcher']);
}
if (isset($options['collectors'])) {
$this->setCollectors($options['collectors']);
}
}
/**
* Sets Event-level profiling options.
*
* @param array $options
*/
public function setEvents(array $options)
{
if (isset($options['enabled'])) {
$this->events['enabled'] = (bool) $options['enabled'];
}
if (isset($options['collectors'])) {
$this->setEventCollectors($options['collectors']);
}
if (isset($options['identifiers'])) {
$this->setEventIdentifiers($options['identifiers']);
}
}
/**
* Sets Profiler matcher options.
*
* @param array $options
*/
protected function setMatcher($options)
{
if (!is_array($options)) {
$this->report->addError(sprintf(
'[\'zenddevelopertools\'][\'profiler\'][\'matcher\'] must be an array, %s given.',
gettype($options)
));
return;
}
$this->profiler['matcher'] = $options;
}
/**
* Sets Profiler collectors options.
*
* @param array $options
*/
protected function setCollectors($options)
{
if (!is_array($options)) {
$this->report->addError(sprintf(
'[\'zenddevelopertools\'][\'profiler\'][\'collectors\'] must be an array, %s given.',
gettype($options)
));
return;
}
foreach ($options as $name => $collector) {
if (($collector === false || $collector === null)) {
unset($this->profiler['collectors'][$name]);
} else {
$this->profiler['collectors'][$name] = $collector;
}
}
}
/**
* Is the Profiler enabled?
*
* @return bool
*/
public function isEnabled()
{
return $this->profiler['enabled'];
}
/**
* Sets Event-level collectors.
*
* @param array $options
*/
public function setEventCollectors(array $options)
{
if (!is_array($options)) {
$this->report->addError(sprintf(
'[\'zenddevelopertools\'][\'events\'][\'collectors\'] must be an array, %s given.',
gettype($options)
));
return;
}
foreach ($options as $name => $collector) {
if (($collector === false || $collector === null)) {
unset($this->events['collectors'][$name]);
} else {
$this->events['collectors'][$name] = $collector;
}
}
}
/**
* Set Event-level collectors to listen to certain event identifiers. Defaults to '*' which causes the listener to
* attach to all events.
*
* @param array $options
*/
public function setEventIdentifiers(array $options)
{
if (!is_array($options)) {
$this->report->addError(sprintf(
'[\'zenddevelopertools\'][\'events\'][\'identifiers\'] must be an array, %s given.',
gettype($options)
));
return;
}
foreach ($options as $name => $identifier) {
if (($identifier === false || $identifier === null)) {
unset($this->events['identifiers'][$name]);
} else {
$this->events['identifiers'][$name] = $identifier;
}
}
}
/**
* Is the event-level statistics collection enabled?
*
* @return bool
*/
public function eventCollectionEnabled()
{
return $this->events['enabled'];
}
/**
* Is strict mode enabled?
*
* @return bool
*/
public function isStrict()
{
return $this->profiler['strict'];
}
/**
* Is it allowed to flush the page before the collector runs?
*
* Note: Only possible if the toolbar, firephp and the strict mode is
* disabled.
*
* @return bool
*/
public function canFlushEarly()
{
return (
$this->profiler['flush_early'] &&
!$this->profiler['strict'] &&
!$this->toolbar['enabled']
);
}
/**
* Returns the cache directory that is used to store the version cache or
* any report storage that writes to the disk.
*
* @return string
*/
public function getCacheDir()
{
return $this->profiler['cache_dir'];
}
// todo: getter for matcher
/**
* Returns the collectors.
*
* @return array
*/
public function getCollectors()
{
return $this->profiler['collectors'];
}
/**
* Returns the event-level collectors.
*
* @return array
*/
public function getEventCollectors()
{
return $this->events['collectors'];
}
/**
* Returns the event identifiers.
*
* @return array
*/
public function getEventIdentifiers()
{
return $this->events['identifiers'];
}
/**
* Sets Toolbar options.
*
* @param array $options
*/
public function setToolbar(array $options)
{
if (isset($options['enabled'])) {
$this->toolbar['enabled'] = (bool) $options['enabled'];
}
if (isset($options['auto_hide'])) {
$this->toolbar['auto_hide'] = (bool) $options['auto_hide'];
}
if (isset($options['version_check'])) {
$this->toolbar['version_check'] = (bool) $options['version_check'];
}
if (isset($options['position'])) {
if ($options['position'] !== 'bottom' && $options['position'] !== 'top') {
$this->report->addError(sprintf(
'[\'zenddevelopertools\'][\'toolbar\'][\'position\'] must be "top" or "bottom", %s given.',
$options['position']
));
} else {
$this->toolbar['position'] = $options['position'];
}
}
if (isset($options['entries'])) {
if (is_array($options['entries'])) {
foreach ($options['entries'] as $collector => $template) {
if ($template === false || $template === null) {
unset($this->toolbar['entries'][$collector]);
} else {
$this->toolbar['entries'][$collector] = $template;
}
}
} else {
$this->report->addError(sprintf(
'[\'zenddevelopertools\'][\'toolbar\'][\'entries\'] must be an array, %s given.',
gettype($options['entries'])
));
}
}
}
/**
* Is the Toolbar enabled?
*
* @return bool
*/
public function isToolbarEnabled()
{
return $this->toolbar['enabled'];
}
/**
* Is the Zend Framework version check enabled?
*
* @return bool
*/
public function isVersionCheckEnabled()
{
return $this->toolbar['version_check'];
}
/**
* Can hide Toolbar entries?
*
* @return bool
*/
public function getToolbarAutoHide()
{
return $this->toolbar['auto_hide'];
}
/**
* Returns the Toolbar position.
*
* @return array
*/
public function getToolbarPosition()
{
return $this->toolbar['position'];
}
/**
* Returns the Toolbar entries.
*
* @return array
*/
public function getToolbarEntries()
{
return $this->toolbar['entries'];
}
/**
* Sets BackgroundRequest options.
*
* @param array $options
*/
public function setBackgroundrequests($options)
{
if (isset($options['enabled'])) {
$this->backgroundrequests['enabled'] = (bool) $options['enabled'];
}
}
/**
* Is the background-request-collection enabled?
*
* @return bool
*/
public function isBackgroundrequestsEnabled()
{
return $this->backgroundrequests['enabled'];
}
// todo: storage and firephp options.
}