1 | <?php |
||
12 | class LogEnvelope |
||
13 | { |
||
14 | private $config = []; |
||
15 | private $cachedConfig = []; |
||
16 | |||
17 | public function __construct() |
||
18 | { |
||
19 | $this->config['censored_fields'] = config('yaro.log-envelope.censored_fields', ['password']); |
||
20 | $this->config['except'] = config('yaro.log-envelope.except', []); |
||
21 | $this->config['count'] = config('yaro.log-envelope.lines_count', 6); |
||
22 | $this->config['drivers'] = config('yaro.log-envelope.drivers', []); |
||
23 | } // end __construct |
||
24 | |||
25 | public function send($exception) |
||
26 | { |
||
27 | $this->onBefore(); |
||
28 | |||
29 | try { |
||
30 | $data = $this->getExceptionData($exception); |
||
31 | |||
32 | if ($this->isSkipException($data['class'])) { |
||
33 | return; |
||
34 | } |
||
35 | |||
36 | foreach ($this->config['drivers'] as $driver => $driverConfig) { |
||
37 | DriverFactory::create($driver, $data)->setConfig($driverConfig)->send(); |
||
38 | } |
||
39 | } catch (Exception $e) { |
||
40 | Log::error($e); |
||
41 | } |
||
42 | |||
43 | $this->onAfter(); |
||
44 | } // end send |
||
45 | |||
46 | private function onBefore() |
||
47 | { |
||
48 | $this->cachedConfig = []; |
||
49 | $forcedConfig = config('yaro.log-envelope.force_config', []); |
||
50 | foreach ($forcedConfig as $configKey => $configValue) { |
||
51 | $this->cachedConfig[$configKey] = config($configKey); |
||
52 | } |
||
53 | if ($forcedConfig) { |
||
54 | config($forcedConfig); |
||
55 | } |
||
56 | } // end onBefore |
||
57 | |||
58 | private function onAfter() |
||
59 | { |
||
60 | if ($this->cachedConfig) { |
||
|
|||
61 | config($this->cachedConfig); |
||
62 | } |
||
63 | } // end onAfter |
||
64 | |||
65 | public function isSkipException($exceptionClass) |
||
69 | |||
70 | private function getExceptionData($exception) |
||
71 | { |
||
72 | $data = []; |
||
73 | |||
128 | |||
129 | /** |
||
130 | * Set the value of specified fields to ***** |
||
131 | * |
||
132 | * @param string $value |
||
133 | * @param string $key |
||
134 | * @return void |
||
135 | */ |
||
136 | public function censorSensitiveFields(&$value, $key) |
||
142 | |||
143 | /** |
||
144 | * @param SplFileObject $file |
||
145 | */ |
||
146 | private function getLineInfo($file, $line, $i) |
||
165 | } |
||
166 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.