1 | <?php |
||
14 | abstract class Logger implements LoggerInterface { |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $dir; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $prefix; |
||
25 | |||
26 | /** |
||
27 | * @var boolean |
||
28 | */ |
||
29 | protected $ondebug; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $_messages = array(); |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $_errors = array(); |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $_debugs = array(); |
||
45 | |||
46 | /** |
||
47 | * Logger constructor |
||
48 | * |
||
49 | */ |
||
50 | public function __construct($dir, $prefix='my', $debug=false) |
||
51 | { |
||
52 | $this->dir = $dir; |
||
53 | $this->prefix = $prefix; |
||
54 | $this->ondebug = $debug; |
||
55 | |||
56 | if ($this->ondebug === TRUE) |
||
57 | { |
||
58 | $this->_debugs[] = PHP_EOL . $this->log_debug_event('start'); |
||
59 | } |
||
60 | |||
61 | register_shutdown_function(array($this, 'shutdown')); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Add message to logger buffer |
||
66 | * |
||
67 | * @param string $message Message text |
||
68 | * |
||
69 | */ |
||
70 | public function add($message) |
||
75 | |||
76 | /** |
||
77 | * Add error message to logger buffer |
||
78 | * |
||
79 | * @param string $message Message text |
||
80 | * |
||
81 | */ |
||
82 | public function error($message) |
||
87 | |||
88 | /** |
||
89 | * Add debug message to logger buffer |
||
90 | * |
||
91 | * @param string $message Message to log |
||
92 | * |
||
93 | */ |
||
94 | public function debug($message) |
||
101 | |||
102 | /** |
||
103 | * Finish and sync all buffers to files |
||
104 | * |
||
105 | */ |
||
106 | public function shutdown() |
||
107 | { |
||
108 | if ($this->ondebug === TRUE) |
||
109 | { |
||
110 | $this->_debugs[] = $this->log_debug_event('end') . PHP_EOL; |
||
111 | } |
||
112 | $this->sync(); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Sync all buffers to files |
||
117 | * |
||
118 | */ |
||
119 | public function sync() |
||
139 | |||
140 | /** |
||
141 | * Get formated string of debug event |
||
142 | * |
||
143 | * @param string $event Name of event |
||
144 | * @return string |
||
145 | */ |
||
146 | protected function log_debug_event($event) |
||
150 | |||
151 | /** |
||
152 | * Get formatted timestamp |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | protected function log_timestamp() |
||
160 | |||
161 | /** |
||
162 | * Write text to file |
||
163 | * |
||
164 | * @param string $messages |
||
165 | * @param string $file |
||
166 | * |
||
167 | * @throws Exception |
||
168 | * |
||
169 | */ |
||
170 | protected function write($messages, $file) |
||
185 | } |
||
186 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: