Example #1
0
 /**
  * @param Runner $runner
  * @param array $loggers
  */
 public function __construct(Runner $runner, Accept $accept, array $loggers = array(), array $availableFormatters = array())
 {
     $this->errorHandler = $runner;
     $this->loggers = $loggers;
     if ($availableFormatters) {
         $possibleAccepts = array_keys($availableFormatters);
         $result = $accept->negotiateMedia($possibleAccepts);
         if ($result) {
             $this->errorHandler->pushFormatter($availableFormatters[$result->getValue()]);
         }
     }
     foreach ($loggers as $name => $logger) {
         if ($name == 'event') {
             ModusLogger::registerLogger($logger);
         } else {
             ModusLogger::registerLogger($logger, $name);
         }
     }
 }
Example #2
0
 public function register()
 {
     $di = $this->getContainer();
     $config = $this->getConfig();
     $di->add('League\\BooBoo\\Handler\\LogHandler')->withArgument('Psr\\Log\\LoggerInterface');
     $di->add('Laasti\\Core\\Exceptions\\LogHandler')->withArgument('Psr\\Log\\LoggerInterface');
     $di->add('League\\BooBoo\\Formatter\\HtmlTableFormatter');
     if ($di->has('peels.exceptions')) {
         $di->add('error_formatter.kernel', 'Laasti\\Http\\HttpKernel')->withArgument('peels.exceptions');
         $args = ['error_formatter.kernel', 'peels.exceptions'];
     } else {
         $di->add('error_formatter.kernel', 'Laasti\\Http\\HttpKernel')->withArgument('error_formatter.callable');
         $args = ['error_formatter.kernel'];
     }
     $self = $this;
     $di->share('error_formatter', function ($kernel, $runner, $request, $response) use($config, $self) {
         $formatter = new \Laasti\Core\Exceptions\PrettyBooBooFormatter($kernel, $runner);
         foreach ($config['exception_handlers'] as $exceptionClass => $handler) {
             $formatter->setHandler($exceptionClass, $self->resolve($handler));
         }
         $formatter->setRequest($request)->setResponse($response);
         return $formatter;
     })->withArguments(array_merge($args, ['request', 'response']));
     $di->share('League\\BooBoo\\Runner', function () use($di, $config) {
         $runner = new Runner();
         foreach ($config['formatters'] as $containerKey => $error_level) {
             $formatter = $di->get($containerKey);
             $formatter->setErrorLimit($error_level);
             $runner->pushFormatter($formatter);
         }
         foreach ($config['handlers'] as $containerKey) {
             $handler = $di->get($containerKey);
             $runner->pushHandler($handler);
         }
         if (isset($config['pretty_page'])) {
             $runner->setErrorPageFormatter($di->get($config['pretty_page']));
         }
         return $runner;
     });
     $di->add('error_handler', function () use($di) {
         return [$di->get('League\\BooBoo\\Runner'), 'register'];
     });
 }
 /**
  * Register BooBoo error handler.
  */
 public function register()
 {
     $runner = new Runner();
     foreach ($this->formatters as $formatter) {
         $runner->pushFormatter($formatter);
     }
     if (count($this->formatters) === 0) {
         $runner->pushFormatter(new NullFormatter());
     }
     foreach ($this->handlers as $handler) {
         $runner->pushHandler($handler);
     }
     $runner->register();
 }