@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Micro |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param Iterable $config |
| 58 | 58 | * @return void |
| 59 | 59 | */ |
| 60 | - public function __construct(?Iterable $config=null) |
|
| 60 | + public function __construct(? Iterable $config = null) |
|
| 61 | 61 | { |
| 62 | 62 | $this->setOptions($config); |
| 63 | 63 | } |
@@ -69,14 +69,14 @@ discard block |
||
| 69 | 69 | * @param Iterable $config |
| 70 | 70 | * @return Log |
| 71 | 71 | */ |
| 72 | - public function setOptions(?Iterable $config=null) |
|
| 72 | + public function setOptions(? Iterable $config = null) |
|
| 73 | 73 | { |
| 74 | - if($config === null) { |
|
| 74 | + if ($config === null) { |
|
| 75 | 75 | return $this; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - foreach($config as $option => $value) { |
|
| 79 | - if(!isset($value['enabled']) || $value['enabled'] === '1') { |
|
| 78 | + foreach ($config as $option => $value) { |
|
| 79 | + if (!isset($value['enabled']) || $value['enabled'] === '1') { |
|
| 80 | 80 | $this->addAdapter($option, $value['class'], $value['config']); |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -105,14 +105,14 @@ discard block |
||
| 105 | 105 | * @param Iterable $config |
| 106 | 106 | * @return AdapterInterface |
| 107 | 107 | */ |
| 108 | - public function addAdapter(string $name, string $class, ?Iterable $config=null): AdapterInterface |
|
| 108 | + public function addAdapter(string $name, string $class, ? Iterable $config = null) : AdapterInterface |
|
| 109 | 109 | { |
| 110 | - if($this->hasAdapter($name)) { |
|
| 110 | + if ($this->hasAdapter($name)) { |
|
| 111 | 111 | throw new Exception('log adapter '.$name.' is already registered'); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $adapter = new $class($config); |
| 115 | - if(!($adapter instanceof AdapterInterface)) { |
|
| 115 | + if (!($adapter instanceof AdapterInterface)) { |
|
| 116 | 116 | throw new Exception('log adapter must include AdapterInterface interface'); |
| 117 | 117 | } |
| 118 | 118 | $this->adapter[$name] = $adapter; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function getAdapter(string $name): AdapterInterface |
| 130 | 130 | { |
| 131 | - if(!$this->hasAdapter($name)) { |
|
| 131 | + if (!$this->hasAdapter($name)) { |
|
| 132 | 132 | throw new Exception('log adapter '.$name.' is not registered'); |
| 133 | 133 | } |
| 134 | 134 | |
@@ -142,14 +142,14 @@ discard block |
||
| 142 | 142 | * @param array $adapters |
| 143 | 143 | * @return array |
| 144 | 144 | */ |
| 145 | - public function getAdapters(array $adapters=[]): array |
|
| 145 | + public function getAdapters(array $adapters = []): array |
|
| 146 | 146 | { |
| 147 | - if(empty($adapter)) { |
|
| 147 | + if (empty($adapter)) { |
|
| 148 | 148 | return $this->adapter; |
| 149 | 149 | } else { |
| 150 | 150 | $list = []; |
| 151 | - foreach($adapter as $name) { |
|
| 152 | - if(!$this->hasAdapter($name)) { |
|
| 151 | + foreach ($adapter as $name) { |
|
| 152 | + if (!$this->hasAdapter($name)) { |
|
| 153 | 153 | throw new Exception('log adapter '.$name.' is not registered'); |
| 154 | 154 | } |
| 155 | 155 | $list[$name] = $this->adapter[$name]; |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * @param array $context |
| 170 | 170 | * @return bool |
| 171 | 171 | */ |
| 172 | - public function log($level, $message, array $context=[]): bool |
|
| 172 | + public function log($level, $message, array $context = []): bool |
|
| 173 | 173 | { |
| 174 | 174 | if (!array_key_exists($level, self::PRIORITIES)) { |
| 175 | 175 | throw new Exception('log level '.$level.' is unkown'); |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | * @param array $context |
| 213 | 213 | * @return void |
| 214 | 214 | */ |
| 215 | - protected function _format(string $message, string $format, string $date_format, string $level, array $context=[]): string |
|
| 215 | + protected function _format(string $message, string $format, string $date_format, string $level, array $context = []): string |
|
| 216 | 216 | { |
| 217 | - $parsed = preg_replace_callback('/(\{(([a-z]\.*)+)\})/', function ($match) use ($message, $level, $date_format, $context) { |
|
| 217 | + $parsed = preg_replace_callback('/(\{(([a-z]\.*)+)\})/', function($match) use ($message, $level, $date_format, $context) { |
|
| 218 | 218 | $key = ''; |
| 219 | 219 | $context = array_merge($this->context, $context); |
| 220 | 220 | |
@@ -237,9 +237,9 @@ discard block |
||
| 237 | 237 | $replace = []; |
| 238 | 238 | foreach ($context as $key => $val) { |
| 239 | 239 | if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) { |
| 240 | - $replace['{' . $key . '}'] = $val; |
|
| 240 | + $replace['{'.$key.'}'] = $val; |
|
| 241 | 241 | } else { |
| 242 | - $replace['{' . $key . '}'] = json_encode($val); |
|
| 242 | + $replace['{'.$key.'}'] = json_encode($val); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |