|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Xhgui\Profiler; |
| 4 | + |
| 5 | +use ArrayAccess; |
| 6 | + |
| 7 | +class Config implements ArrayAccess |
| 8 | +{ |
| 9 | + /** @var array */ |
| 10 | + private $config; |
| 11 | + |
| 12 | + public function __construct(array $config = array()) |
| 13 | + { |
| 14 | + $this->config = $this->getDefaultConfig(); |
| 15 | + if ($config) { |
| 16 | + $this->merge($config); |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * @return array |
| 22 | + */ |
| 23 | + public function toArray() |
| 24 | + { |
| 25 | + return $this->config; |
| 26 | + } |
| 27 | + |
| 28 | + private function merge(array $config) |
| 29 | + { |
| 30 | + $this->config = array_replace($this->config, $config); |
| 31 | + } |
| 32 | + |
| 33 | + public function offsetExists($offset) |
| 34 | + { |
| 35 | + return isset($this->config[$offset]); |
| 36 | + } |
| 37 | + |
| 38 | + public function offsetGet($offset) |
| 39 | + { |
| 40 | + return $this->config[$offset]; |
| 41 | + } |
| 42 | + |
| 43 | + public function offsetSet($offset, $value) |
| 44 | + { |
| 45 | + $this->config[$offset] = $value; |
| 46 | + } |
| 47 | + |
| 48 | + public function offsetUnset($offset) |
| 49 | + { |
| 50 | + unset($this->config[$offset]); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @return array |
| 55 | + */ |
| 56 | + private function getDefaultConfig() |
| 57 | + { |
| 58 | + return array( |
| 59 | + 'save.handler' => Profiler::SAVER_STACK, |
| 60 | + 'save.handler.stack' => array( |
| 61 | + 'savers' => array( |
| 62 | + Profiler::SAVER_UPLOAD, |
| 63 | + Profiler::SAVER_FILE, |
| 64 | + ), |
| 65 | + 'saveAll' => false, |
| 66 | + ), |
| 67 | + 'save.handler.file' => array( |
| 68 | + 'filename' => sys_get_temp_dir() . '/xhgui.data.jsonl', |
| 69 | + ), |
| 70 | + 'profiler.enable' => function () { |
| 71 | + return true; |
| 72 | + }, |
| 73 | + 'profiler.flags' => array( |
| 74 | + ProfilingFlags::CPU, |
| 75 | + ProfilingFlags::MEMORY, |
| 76 | + ProfilingFlags::NO_BUILTINS, |
| 77 | + ProfilingFlags::NO_SPANS, |
| 78 | + ), |
| 79 | + 'profiler.options' => array(), |
| 80 | + 'profiler.exclude-env' => array(), |
| 81 | + 'profiler.simple_url' => function ($url) { |
| 82 | + return preg_replace('/=\d+/', '', $url); |
| 83 | + }, |
| 84 | + 'profiler.replace_url' => null, |
| 85 | + ); |
| 86 | + } |
| 87 | +} |
0 commit comments