@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use nebula\component\request\Request; |
7 | 7 | use nebula\component\debug\log\logger\FileLogger; |
8 | 8 | |
9 | -require_once __DIR__ .'/../vendor/autoload.php'; |
|
9 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
10 | 10 | |
11 | 11 | $logger = new FileLogger( |
12 | 12 | [ |
@@ -30,19 +30,19 @@ discard block |
||
30 | 30 | $debug->timeEnd('Request::buildFromServer'); |
31 | 31 | |
32 | 32 | $debug->debug('request apply true', [ |
33 | - 'request' => $request , |
|
33 | + 'request' => $request, |
|
34 | 34 | 'exception' => new Exception('test exception') |
35 | 35 | ]); |
36 | 36 | |
37 | 37 | $debug->debug('request getBasicURI {url}', ['url' => $request->getBasicURI()]); |
38 | 38 | |
39 | -function formatBytes(int $bytes, int $precision=0) |
|
39 | +function formatBytes(int $bytes, int $precision = 0) |
|
40 | 40 | { |
41 | - $human= ['B', 'KB', 'MB', 'GB', 'TB']; |
|
41 | + $human = ['B', 'KB', 'MB', 'GB', 'TB']; |
|
42 | 42 | $bytes = max($bytes, 0); |
43 | - $pow = floor(($bytes?log($bytes):0)/log(1024)); |
|
44 | - $pos = min($pow, count($human)-1); |
|
45 | - $bytes /= (1 << (10* $pos)); |
|
43 | + $pow = floor(($bytes ?log($bytes) : 0) / log(1024)); |
|
44 | + $pos = min($pow, count($human) - 1); |
|
45 | + $bytes /= (1 << (10 * $pos)); |
|
46 | 46 | return round($bytes, $precision).' '.$human[$pos]; |
47 | 47 | } |
48 | 48 |
@@ -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 | protected $times; |
22 | 22 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | $replace = []; |
48 | 48 | foreach ($context as $key => $val) { |
49 | - $replace['{' . $key . '}'] = $val; |
|
49 | + $replace['{'.$key.'}'] = $val; |
|
50 | 50 | } |
51 | 51 | return strtr($message, $replace); |
52 | 52 | } |
@@ -62,26 +62,26 @@ discard block |
||
62 | 62 | return $attribute; |
63 | 63 | } |
64 | 64 | |
65 | - protected static function formatBytes(int $bytes, int $precision=0) |
|
65 | + protected static function formatBytes(int $bytes, int $precision = 0) |
|
66 | 66 | { |
67 | - $human= ['B', 'KB', 'MB', 'GB', 'TB']; |
|
67 | + $human = ['B', 'KB', 'MB', 'GB', 'TB']; |
|
68 | 68 | $bytes = max($bytes, 0); |
69 | - $pow = floor(($bytes?log($bytes):0)/log(1024)); |
|
70 | - $pos = min($pow, count($human)-1); |
|
71 | - $bytes /= (1 << (10* $pos)); |
|
69 | + $pow = floor(($bytes ?log($bytes) : 0) / log(1024)); |
|
70 | + $pos = min($pow, count($human) - 1); |
|
71 | + $bytes /= (1 << (10 * $pos)); |
|
72 | 72 | return round($bytes, $precision).' '.$human[$pos]; |
73 | 73 | } |
74 | 74 | |
75 | - public function time(string $name, string $type= LogLevel::INFO) |
|
75 | + public function time(string $name, string $type = LogLevel::INFO) |
|
76 | 76 | { |
77 | - $this->time[$name]=['time'=>microtime(true),'level'=>$type]; |
|
77 | + $this->time[$name] = ['time'=>microtime(true), 'level'=>$type]; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public function timeEnd(string $name) |
81 | 81 | { |
82 | 82 | if (\array_key_exists($name, $this->time)) { |
83 | - $pass=microtime(true)-$this->time[$name]['time']; |
|
84 | - $this->log($this->time[$name]['level'], 'process cost '. $name.' '. number_format($pass, 5).'s'); |
|
83 | + $pass = microtime(true) - $this->time[$name]['time']; |
|
84 | + $this->log($this->time[$name]['level'], 'process cost '.$name.' '.number_format($pass, 5).'s'); |
|
85 | 85 | return true; |
86 | 86 | } |
87 | 87 | return false; |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @var array |
13 | 13 | */ |
14 | - protected $attribute=[]; |
|
14 | + protected $attribute = []; |
|
15 | 15 | |
16 | 16 | public function addAttribute(array $value) |
17 | 17 | { |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | protected function analyse(array $context) |
22 | 22 | { |
23 | 23 | $replace = []; |
24 | - $attach =[] ; |
|
24 | + $attach = []; |
|
25 | 25 | foreach ($context as $key => $val) { |
26 | - if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString')) && ! $val instanceof \Exception) { |
|
27 | - $replace['{' . $key . '}'] = $val; |
|
26 | + if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString')) && !$val instanceof \Exception) { |
|
27 | + $replace['{'.$key.'}'] = $val; |
|
28 | 28 | } else { |
29 | 29 | $attach[$key] = $val; |
30 | 30 | } |
@@ -34,19 +34,19 @@ discard block |
||
34 | 34 | |
35 | 35 | public function interpolate(string $message, array $context, array $attribute) |
36 | 36 | { |
37 | - list($attach, $replace) = $this->analyse($context); |
|
37 | + list($attach, $replace) = $this->analyse($context); |
|
38 | 38 | $attribute = array_merge($this->attribute, $attribute); |
39 | 39 | foreach ($attribute as $key => $val) { |
40 | - $replace['%' . $key . '%'] = $val; |
|
40 | + $replace['%'.$key.'%'] = $val; |
|
41 | 41 | } |
42 | 42 | $message = strtr($message, $replace); |
43 | 43 | $attachInfo = ''; |
44 | 44 | foreach ($attach as $name => $value) { |
45 | 45 | $attachInfo = $name.' = '; |
46 | 46 | if ($value instanceof AttachValueInterface) { |
47 | - $attachInfo.= $value->getLogAttach().PHP_EOL; |
|
47 | + $attachInfo .= $value->getLogAttach().PHP_EOL; |
|
48 | 48 | } else { |
49 | - $attachInfo.= DumpTrait::parameterToString($value).PHP_EOL; |
|
49 | + $attachInfo .= DumpTrait::parameterToString($value).PHP_EOL; |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | if (strlen($attachInfo) > 0) { |