/** * @param $bool * @throws \Savage\BooBoo\Exception\NoFormattersRegisteredException */ public function registerErrorHandler($bool) { if ($bool) { $this->errorHandler->register(); } else { $this->errorHandler->deregister(); } }
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']; }); }
/** * @param string $vendor * @param string $apiVersion * @param bool $debug */ public function __construct($vendor, $apiVersion, $debug = false) { if (!preg_match('#^' . Application::API_VERSION_REG_EXP . '$#', (string) $apiVersion)) { throw new \InvalidArgumentException('Api version is not valid'); } $this->vendor = $vendor; $this->apiVersion = $apiVersion; $this->debug = $debug; $this->setContainer(new Container()); $this->setRouter(new RouteCollection($this->getContainer())); $this->setEventEmitter(new EventEmitter()); $this->setHateoasConfig(new HateoasConfig($debug)); $this->setHateoasService(new HateoasService()); $this->setLoggerConfig(new LoggerConfig('phprest')); $this->setLoggerService(new LoggerService()); $this->setLogHandler(new LogHandler()); $this->setRouterStrategy(new RouterStrategy($this->getContainer())); $errorHandler = new Runner([new JsonXmlFormatter($this)]); $errorHandler->silenceAllErrors(false); $errorHandler->treatErrorsAsExceptions(true); $this->setErrorHandler($errorHandler); }
/** * 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(); }