1
|
|
|
<?php |
2
|
|
|
namespace PHP; |
3
|
|
|
|
4
|
|
|
class ArrayDebugger extends \ArrayObject { |
5
|
|
|
|
6
|
|
|
const TYPE_GET = 'GET'; |
7
|
|
|
const TYPE_SET = 'SET'; |
8
|
|
|
const TYPE_EXISTS = 'EXISTS'; |
9
|
|
|
const TYPE_UNSET = 'UNSET'; |
10
|
|
|
|
11
|
|
|
private $logger; |
12
|
|
|
|
13
|
|
|
public function __construct() { |
14
|
|
|
|
15
|
|
|
$this->logger = function($data_log) { |
16
|
|
|
return dump($data_log); |
17
|
|
|
}; |
18
|
|
|
|
19
|
|
|
return call_user_func_array('parent::__construct', func_get_args()); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function sendLog($type, $key, $value = null, array $backtrace ) { |
23
|
|
|
|
24
|
|
|
$logger = $this->logger; |
25
|
|
|
$retorno['type'] = $type; |
|
|
|
|
26
|
|
|
$retorno['key'] = $key; |
27
|
|
|
$retorno['value'] = $value; |
28
|
|
|
$retorno['file'] = $backtrace[0]['file']; |
29
|
|
|
$retorno['line'] = $backtrace[0]['line']; |
30
|
|
|
return $logger($retorno); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function setLogger(\Closure $logger) { |
34
|
|
|
$this->logger = $logger; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function offsetGet($name) { |
38
|
|
|
|
39
|
|
|
$this->sendLog(static::TYPE_GET, $name, null, debug_backtrace()); |
40
|
|
|
return call_user_func_array('parent::offsetGet', func_get_args()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function offsetSet($name, $value) { |
44
|
|
|
|
45
|
|
|
$this->sendLog(static::TYPE_SET, $name, $value, debug_backtrace()); |
46
|
|
|
return call_user_func_array('parent::offsetSet', func_get_args()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function offsetExists($name) { |
50
|
|
|
|
51
|
|
|
$this->sendLog(static::TYPE_EXISTS, $name, null, debug_backtrace()); |
52
|
|
|
return call_user_func_array('parent::offsetExists', func_get_args()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function offsetUnset($name) { |
56
|
|
|
|
57
|
|
|
$this->sendLog(static::TYPE_UNSET, $name, null, debug_backtrace()); |
58
|
|
|
return call_user_func_array('parent::offsetUnset', func_get_args()); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|