@@ -60,6 +60,9 @@ discard block |
||
| 60 | 60 | return $this->createLogger($container, $requestedName); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | + /** |
|
| 64 | + * @param ContainerInterface $container |
|
| 65 | + */ |
|
| 63 | 66 | private function createLogger($container, $requestedName) |
| 64 | 67 | { |
| 65 | 68 | $config = $this->getConfig($container); |
@@ -70,7 +73,7 @@ discard block |
||
| 70 | 73 | |
| 71 | 74 | /** |
| 72 | 75 | * @param ServiceLocatorInterface|ContainerInterface $container |
| 73 | - * @return array |
|
| 76 | + * @return ContainerInterface |
|
| 74 | 77 | */ |
| 75 | 78 | public function getConfig($container) |
| 76 | 79 | { |
@@ -9,7 +9,6 @@ |
||
| 9 | 9 | use Closure; |
| 10 | 10 | use Exception; |
| 11 | 11 | use Interop\Container\ContainerInterface; |
| 12 | -use Monolog\Formatter\LineFormatter; |
|
| 13 | 12 | use Monolog\Handler\HandlerInterface; |
| 14 | 13 | use Monolog\Logger; |
| 15 | 14 | use Monolog\Formatter\FormatterInterface; |
@@ -132,16 +132,16 @@ discard block |
||
| 132 | 132 | /** @var HandlerInterface $instance */ |
| 133 | 133 | $instance = $reflection->newInstanceArgs($parameters); |
| 134 | 134 | } else { |
| 135 | - $class = $handler['name']; |
|
| 135 | + $class = $handler['name']; |
|
| 136 | 136 | |
| 137 | 137 | /** @var HandlerInterface $instance */ |
| 138 | - $instance = new $class(); |
|
| 138 | + $instance = new $class(); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if (isset($handler['formatter'])) { |
|
| 142 | - $formatter = $this->createFormatter($container, $handler['formatter']); |
|
| 143 | - $instance->setFormatter($formatter); |
|
| 144 | - } |
|
| 141 | + if (isset($handler['formatter'])) { |
|
| 142 | + $formatter = $this->createFormatter($container, $handler['formatter']); |
|
| 143 | + $instance->setFormatter($formatter); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | 146 | return $instance; |
| 147 | 147 | } |
@@ -155,34 +155,34 @@ discard block |
||
| 155 | 155 | * @throws \Interop\Container\Exception\ContainerException |
| 156 | 156 | * @throws RuntimeException |
| 157 | 157 | */ |
| 158 | - public function createFormatter($container, $formatter) |
|
| 159 | - { |
|
| 160 | - if (is_string($formatter) && $container->has($formatter)) { |
|
| 161 | - return $container->get($formatter); |
|
| 162 | - } else { |
|
| 163 | - if (!isset($formatter['name'])) { |
|
| 164 | - throw new RuntimeException('Cannot create logger formatter'); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - if (!class_exists($formatter['name'])) { |
|
| 168 | - throw new RuntimeException('Cannot create logger formatter (' . $formatter['name'] . ')'); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - if (isset($formatter['args'])) { |
|
| 172 | - if (!is_array($formatter['args'])) { |
|
| 173 | - throw new RuntimeException('Arguments of formatter(' . $formatter['name'] . ') must be array'); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $reflection = new \ReflectionClass($formatter['name']); |
|
| 177 | - |
|
| 178 | - return call_user_func_array(array($reflection, 'newInstance'), $formatter['args']); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $class = $formatter['name']; |
|
| 182 | - |
|
| 183 | - return new $class(); |
|
| 184 | - } |
|
| 185 | - } |
|
| 158 | + public function createFormatter($container, $formatter) |
|
| 159 | + { |
|
| 160 | + if (is_string($formatter) && $container->has($formatter)) { |
|
| 161 | + return $container->get($formatter); |
|
| 162 | + } else { |
|
| 163 | + if (!isset($formatter['name'])) { |
|
| 164 | + throw new RuntimeException('Cannot create logger formatter'); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + if (!class_exists($formatter['name'])) { |
|
| 168 | + throw new RuntimeException('Cannot create logger formatter (' . $formatter['name'] . ')'); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + if (isset($formatter['args'])) { |
|
| 172 | + if (!is_array($formatter['args'])) { |
|
| 173 | + throw new RuntimeException('Arguments of formatter(' . $formatter['name'] . ') must be array'); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $reflection = new \ReflectionClass($formatter['name']); |
|
| 177 | + |
|
| 178 | + return call_user_func_array(array($reflection, 'newInstance'), $formatter['args']); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $class = $formatter['name']; |
|
| 182 | + |
|
| 183 | + return new $class(); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * @param ServiceLocatorInterface|ContainerInterface $container |
@@ -117,7 +117,7 @@ |
||
| 117 | 117 | throw new RuntimeException(sprintf('Handler(%s) requires at least %d params. Only %d passed.', $handler['name'], $requiredArgsCount, count($handlerOptions))); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - foreach($reflection->getConstructor()->getParameters() as $parameter) { |
|
| 120 | + foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
|
| 121 | 121 | if (!$parameter->isOptional() && !isset($handlerOptions[$parameter->getName()])) { |
| 122 | 122 | $argumentValue = array_shift($handlerOptions); |
| 123 | 123 | } elseif (isset($handlerOptions[$parameter->getName()])) { |