@@ -15,9 +15,9 @@ discard block |
||
15 | 15 | if ($deep > 0) { |
16 | 16 | $vars = get_class_vars($objectName); |
17 | 17 | foreach ($vars as $key => $value) { |
18 | - $parameterString.=static::valueToString($key, $value, $deep); |
|
18 | + $parameterString .= static::valueToString($key, $value, $deep); |
|
19 | 19 | } |
20 | - $parameterString.= static::objectGetter($objectName, $object, $deep); |
|
20 | + $parameterString .= static::objectGetter($objectName, $object, $deep); |
|
21 | 21 | } else { |
22 | 22 | $parameterString = '...'; |
23 | 23 | } |
@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | protected static function objectGetter(string $objectName, object $object, int $deep) |
28 | 28 | { |
29 | 29 | $methods = get_class_methods($objectName); |
30 | - $parameterString =''; |
|
30 | + $parameterString = ''; |
|
31 | 31 | foreach ($methods as $method) { |
32 | 32 | if (strpos($method, 'get') === 0) { |
33 | 33 | $methodRef = new \ReflectionMethod($object, $method); |
34 | 34 | $ignore = \preg_match('/@ignore(-d|D)ump/i', $methodRef->getDocComment()??'') > 0; |
35 | 35 | if (count($methodRef->getParameters()) === 0 && !$ignore) { |
36 | - $parameterString.=static::valueToString($method.'()', $object->$method(), $deep); |
|
36 | + $parameterString .= static::valueToString($method.'()', $object->$method(), $deep); |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $parameterString = ''; |
46 | 46 | if ($deep > 0) { |
47 | 47 | foreach ($array as $key => $value) { |
48 | - $parameterString.=static::valueToString($key, $value, $deep); |
|
48 | + $parameterString .= static::valueToString($key, $value, $deep); |
|
49 | 49 | } |
50 | 50 | } else { |
51 | 51 | $parameterString = '...'; |
@@ -64,15 +64,15 @@ discard block |
||
64 | 64 | protected static function valueToString(string $key, $value, int $deep):string |
65 | 65 | { |
66 | 66 | if (is_string($value) && strlen($value) > static::$dumpStringLength) { |
67 | - return $key.'='.json_encode(substr($value, 0, static::$dumpStringLength), JSON_UNESCAPED_UNICODE) .'... ,'; |
|
67 | + return $key.'='.json_encode(substr($value, 0, static::$dumpStringLength), JSON_UNESCAPED_UNICODE).'... ,'; |
|
68 | 68 | } elseif (is_bool($value)) { |
69 | 69 | return $key.'='.($value ? 'true' : 'false').' ,'; |
70 | 70 | } else { |
71 | - return $key.'='.self::parameterToString($value, $deep-1) .' ,'; |
|
71 | + return $key.'='.self::parameterToString($value, $deep - 1).' ,'; |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - public static function parameterToString($object, int $deep=2) |
|
75 | + public static function parameterToString($object, int $deep = 2) |
|
76 | 76 | { |
77 | 77 | if (is_null($object)) { |
78 | 78 | return 'NULL'; |
@@ -86,16 +86,16 @@ discard block |
||
86 | 86 | return $object; |
87 | 87 | } |
88 | 88 | |
89 | - public static function dumpTrace(array $backtrace, bool $str=true, string $perfix='') |
|
89 | + public static function dumpTrace(array $backtrace, bool $str = true, string $perfix = '') |
|
90 | 90 | { |
91 | - $tracesConsole=[]; |
|
91 | + $tracesConsole = []; |
|
92 | 92 | foreach ($backtrace as $trace) { |
93 | - $tracesConsole[]=static::buildTraceLine($trace); |
|
93 | + $tracesConsole[] = static::buildTraceLine($trace); |
|
94 | 94 | } |
95 | 95 | if ($str) { |
96 | - $str=''; |
|
96 | + $str = ''; |
|
97 | 97 | foreach ($tracesConsole as $trace_info) { |
98 | - $str.=$perfix.preg_replace('/\n/', "\n".$perfix."\t", $trace_info).PHP_EOL; |
|
98 | + $str .= $perfix.preg_replace('/\n/', "\n".$perfix."\t", $trace_info).PHP_EOL; |
|
99 | 99 | } |
100 | 100 | return $str; |
101 | 101 | } |
@@ -113,22 +113,22 @@ discard block |
||
113 | 113 | } else { |
114 | 114 | $function = $trace['function']; |
115 | 115 | } |
116 | - $argsDump=''; |
|
116 | + $argsDump = ''; |
|
117 | 117 | if (!empty($trace['args'])) { |
118 | 118 | foreach ($trace['args'] as $arg) { |
119 | - $argsDump.= self::parameterToString($arg) .','; |
|
119 | + $argsDump .= self::parameterToString($arg).','; |
|
120 | 120 | } |
121 | 121 | $argsDump = rtrim($argsDump, ','); |
122 | 122 | } |
123 | - $line.=' '.$function.'('.$argsDump.')'; |
|
123 | + $line .= ' '.$function.'('.$argsDump.')'; |
|
124 | 124 | return $line; |
125 | 125 | } |
126 | 126 | |
127 | 127 | public static function dumpException(\Exception $e) |
128 | 128 | { |
129 | - $dump = get_class($e).':'. $e->getMessage() .PHP_EOL; |
|
130 | - $dump.= 'At: ' . $e->getFile().':'.$e->getLine().PHP_EOL; |
|
131 | - $dump.= static::dumpTrace($e->getTrace()); |
|
129 | + $dump = get_class($e).':'.$e->getMessage().PHP_EOL; |
|
130 | + $dump .= 'At: '.$e->getFile().':'.$e->getLine().PHP_EOL; |
|
131 | + $dump .= static::dumpTrace($e->getTrace()); |
|
132 | 132 | return $dump; |
133 | 133 | } |
134 | 134 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | class Debug implements LoggerInterface, LoggerAwareInterface, DumpInterface, AttachInterface, ConfigInterface |
18 | 18 | { |
19 | - use LoggerTrait,LoggerAwareTrait,DumpTrait,AttachTrait,ConfigTrait; |
|
19 | + use LoggerTrait, LoggerAwareTrait, DumpTrait, AttachTrait, ConfigTrait; |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * 时间记录 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | { |
52 | 52 | $replace = []; |
53 | 53 | foreach ($context as $key => $val) { |
54 | - $replace['{' . $key . '}'] = $val; |
|
54 | + $replace['{'.$key.'}'] = $val; |
|
55 | 55 | } |
56 | 56 | return strtr($message, $replace); |
57 | 57 | } |
@@ -67,26 +67,26 @@ discard block |
||
67 | 67 | return $attribute; |
68 | 68 | } |
69 | 69 | |
70 | - protected static function formatBytes(int $bytes, int $precision=0) |
|
70 | + protected static function formatBytes(int $bytes, int $precision = 0) |
|
71 | 71 | { |
72 | - $human= ['B', 'KB', 'MB', 'GB', 'TB']; |
|
72 | + $human = ['B', 'KB', 'MB', 'GB', 'TB']; |
|
73 | 73 | $bytes = max($bytes, 0); |
74 | - $pow = floor(($bytes?log($bytes):0)/log(1024)); |
|
75 | - $pos = min($pow, count($human)-1); |
|
76 | - $bytes /= (1 << (10* $pos)); |
|
74 | + $pow = floor(($bytes ?log($bytes) : 0) / log(1024)); |
|
75 | + $pos = min($pow, count($human) - 1); |
|
76 | + $bytes /= (1 << (10 * $pos)); |
|
77 | 77 | return round($bytes, $precision).' '.$human[$pos]; |
78 | 78 | } |
79 | 79 | |
80 | - public function time(string $name, string $type= LogLevel::INFO) |
|
80 | + public function time(string $name, string $type = LogLevel::INFO) |
|
81 | 81 | { |
82 | - $this->timeRecord[$name]=['time'=>microtime(true),'level'=>$type]; |
|
82 | + $this->timeRecord[$name] = ['time'=>microtime(true), 'level'=>$type]; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | public function timeEnd(string $name) |
86 | 86 | { |
87 | 87 | if (\array_key_exists($name, $this->timeRecord)) { |
88 | - $pass=microtime(true)-$this->timeRecord[$name]['time']; |
|
89 | - $this->log($this->timeRecord[$name]['level'], 'process cost '. $name.' '. number_format($pass, 5).'s'); |
|
88 | + $pass = microtime(true) - $this->timeRecord[$name]['time']; |
|
89 | + $this->log($this->timeRecord[$name]['level'], 'process cost '.$name.' '.number_format($pass, 5).'s'); |
|
90 | 90 | return $pass; |
91 | 91 | } |
92 | 92 | return 0; |
@@ -9,13 +9,13 @@ |
||
9 | 9 | protected $ignorePath = [__FILE__]; |
10 | 10 | protected $backtrace; |
11 | 11 | |
12 | - public function __construct(array $backtrace, array $ignorePath =[]) |
|
12 | + public function __construct(array $backtrace, array $ignorePath = []) |
|
13 | 13 | { |
14 | 14 | $this->ignorePath = \array_merge($this->ignorePath, $ignorePath); |
15 | 15 | $this->backtrace = $backtrace; |
16 | 16 | } |
17 | 17 | |
18 | - public function getCallerTrace():?array |
|
18 | + public function getCallerTrace(): ?array |
|
19 | 19 | { |
20 | 20 | foreach ($this->backtrace as $trace) { |
21 | 21 | if (array_key_exists('file', $trace)) { |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | * @throws FileLoggerException |
47 | 47 | * @param array $config |
48 | 48 | */ |
49 | - public function __construct(array $config=[]) |
|
49 | + public function __construct(array $config = []) |
|
50 | 50 | { |
51 | 51 | $this->applyConfig($config); |
52 | 52 | $temp = tmpfile(); |
53 | 53 | if ($temp === false) { |
54 | - $this->tempname = $this->getConfig('save-path').'/log-'. microtime(true).'.tmp'; |
|
54 | + $this->tempname = $this->getConfig('save-path').'/log-'.microtime(true).'.tmp'; |
|
55 | 55 | $temp = fopen($this->tempname, 'w+'); |
56 | 56 | } |
57 | 57 | if ($temp !== false) { |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | |
78 | 78 | protected function packLogFile() |
79 | 79 | { |
80 | - $logFile= $this->latest; |
|
81 | - $path=preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path') .'/'.date('Y-m-d').'.zip'); |
|
80 | + $logFile = $this->latest; |
|
81 | + $path = preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path').'/'.date('Y-m-d').'.zip'); |
|
82 | 82 | $zip = new ZipArchive; |
83 | 83 | $res = $zip->open($path, ZipArchive::CREATE); |
84 | 84 | if ($res === true) { |
85 | - if ($zip->addFile($logFile, date('Y-m-d'). '-'. $zip->numFiles .'.log')) { |
|
85 | + if ($zip->addFile($logFile, date('Y-m-d').'-'.$zip->numFiles.'.log')) { |
|
86 | 86 | array_push($this->removeFiles, $logFile); |
87 | 87 | } |
88 | 88 | if (\is_dir($this->getConfig('save-pack-path'))) { |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $zip->close(); |
97 | 97 | } else { |
98 | 98 | if (is_file($logFile) && file_exists($logFile)) { |
99 | - rename($logFile, $this->getConfig('save-path') . '/' . date('Y-m-d'). '-'. substr(md5_file($logFile), 0, 8).'.log'); |
|
99 | + rename($logFile, $this->getConfig('save-path').'/'.date('Y-m-d').'-'.substr(md5_file($logFile), 0, 8).'.log'); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function checkSize():bool |
110 | 110 | { |
111 | - $logFile= $this->latest; |
|
111 | + $logFile = $this->latest; |
|
112 | 112 | if (file_exists($logFile)) { |
113 | 113 | if (filesize($logFile) > $this->getConfig('max-file-size')) { |
114 | 114 | return true; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | public function log($level, string $message, array $context = []) |
122 | 122 | { |
123 | - if (LogLevel::compare($level, $this->getConfig('log-level')) >=0) { |
|
123 | + if (LogLevel::compare($level, $this->getConfig('log-level')) >= 0) { |
|
124 | 124 | $replace = []; |
125 | 125 | $message = $this->interpolate($message, $context); |
126 | 126 | $replace['%level%'] = $level; |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | protected function rollLatest() |
134 | 134 | { |
135 | 135 | if (isset($this->latest)) { |
136 | - $size=ftell($this->temp); |
|
136 | + $size = ftell($this->temp); |
|
137 | 137 | fseek($this->temp, 0); |
138 | 138 | if ($size > 0) { |
139 | - $body=fread($this->temp, $size); |
|
139 | + $body = fread($this->temp, $size); |
|
140 | 140 | file_put_contents($this->latest, $body, FILE_APPEND); |
141 | 141 | } |
142 | 142 | fclose($this->temp); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | { |
169 | 169 | $replace = []; |
170 | 170 | foreach ($context as $key => $val) { |
171 | - $replace['{' . $key . '}'] = $val; |
|
171 | + $replace['{'.$key.'}'] = $val; |
|
172 | 172 | } |
173 | 173 | return strtr($message, $replace); |
174 | 174 | } |
@@ -10,13 +10,13 @@ |
||
10 | 10 | { |
11 | 11 | public function log($level, string $message, array $context = []) |
12 | 12 | { |
13 | - print date('Y-m-d H:i:s') .' ' . $this->interpolate($message, $context) . PHP_EOL; |
|
13 | + print date('Y-m-d H:i:s').' '.$this->interpolate($message, $context).PHP_EOL; |
|
14 | 14 | } |
15 | 15 | public function interpolate(string $message, array $context) |
16 | 16 | { |
17 | 17 | $replace = []; |
18 | 18 | foreach ($context as $key => $val) { |
19 | - $replace['{' . $key . '}'] = $val; |
|
19 | + $replace['{'.$key.'}'] = $val; |
|
20 | 20 | } |
21 | 21 | return strtr($message, $replace); |
22 | 22 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace nebula\component\debug; |
3 | 3 | |
4 | -interface ConfigInterface { |
|
4 | +interface ConfigInterface { |
|
5 | 5 | public function applyConfig(array $config); |
6 | 6 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | } |
21 | 21 | public function getConfig(string $name) { |
22 | 22 | $defaultConfig = $this->getDefaultConfig(); |
23 | - return $this->config[$name] ?? $defaultConfig[$name];; |
|
23 | + return $this->config[$name] ?? $defaultConfig[$name]; ; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | abstract public function getDefaultConfig():array; |
@@ -15,14 +15,14 @@ |
||
15 | 15 | * @param int $expire 过期时间 |
16 | 16 | * @return bool |
17 | 17 | */ |
18 | - public function set(string $name, $value, int $expire=null):bool; |
|
18 | + public function set(string $name, $value, int $expire = null):bool; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * 获取值 |
22 | 22 | * @param string $name 名 |
23 | 23 | * @return mixed|null |
24 | 24 | */ |
25 | - public function get(string $name, $defalut=null); |
|
25 | + public function get(string $name, $defalut = null); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * 删除值 |
@@ -40,11 +40,11 @@ |
||
40 | 40 | $exstr = ''; |
41 | 41 | foreach ($array as $key => $value) { |
42 | 42 | $line = ''; |
43 | - $current=$arrname."['".addslashes($key)."']"; |
|
43 | + $current = $arrname."['".addslashes($key)."']"; |
|
44 | 44 | if (is_array($value)) { |
45 | 45 | $line .= self::parserArraySub($current, $value); |
46 | 46 | } else { |
47 | - $line = $current; |
|
47 | + $line = $current; |
|
48 | 48 | if (is_string($value)) { |
49 | 49 | $line .= "='".addslashes($value).'\';'.PHP_EOL; |
50 | 50 | } elseif (is_bool($value)) { |