Commit d68fccdf authored by Tino Goratsch's avatar Tino Goratsch

remove the hard coded error logger from the app bootstrap process

parent 70c7af28
......@@ -9,8 +9,6 @@ namespace ACP3\Core\Application;
use ACP3\Core\Environment\ApplicationMode;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Logger\LoggerFactory;
use Psr\Log\LoggerInterface;
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
......@@ -28,10 +26,6 @@ abstract class AbstractBootstrap implements BootstrapInterface
* @var \ACP3\Core\Environment\ApplicationPath
*/
protected $appPath;
/**
* @var LoggerInterface
*/
protected $logger;
/**
* @param string $appMode
......@@ -42,7 +36,6 @@ abstract class AbstractBootstrap implements BootstrapInterface
{
$this->appMode = $appMode;
$this->initializeApplicationPath();
$this->logger = (new LoggerFactory($this->appPath))->create('error');
}
protected function initializeApplicationPath()
......@@ -60,7 +53,6 @@ abstract class AbstractBootstrap implements BootstrapInterface
ExceptionHandler::register($debug);
$errorHandler = new ErrorHandler();
$errorHandler->setDefaultLogger($this->logger);
ErrorHandler::register($errorHandler);
}
......
......@@ -7,6 +7,7 @@
namespace ACP3\Core\Application;
use ACP3\Core\Application\Event\OutputPageExceptionEvent;
use ACP3\Core\Application\Exception\MaintenanceModeActiveException;
use ACP3\Core\Controller\Exception\ForwardControllerActionAwareExceptionInterface;
use ACP3\Core\DependencyInjection\ServiceContainerBuilder;
......@@ -84,7 +85,7 @@ class Bootstrap extends AbstractBootstrap
/**
* {@inheritdoc}
*
* @throws \Exception
* @throws \Throwable
*/
public function outputPage()
{
......@@ -104,8 +105,11 @@ class Bootstrap extends AbstractBootstrap
$response = $controllerActionDispatcher->dispatch($e->getServiceId(), $e->routeParams());
} catch (MaintenanceModeActiveException $e) {
$response = new Response($e->getMessage(), $e->getCode());
} catch (\Exception $e) {
$this->logger->critical($e);
} catch (\Throwable $e) {
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher */
$eventDispatcher = $this->container->get('core.event_dispatcher');
$eventDispatcher->dispatch('core.output_page_exception', new OutputPageExceptionEvent($e));
throw $e;
}
......
<?php
/**
* Copyright (c) by the ACP3 Developers.
* See the LICENSE file at the top-level module directory for licensing details.
*/
namespace ACP3\Core\Application\Event\Listener;
use ACP3\Core\Application\Event\OutputPageExceptionEvent;
use Psr\Log\LoggerInterface;
class OnOutputPageExceptionListener
{
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function __invoke(OutputPageExceptionEvent $event): void
{
$this->logger->error($event->getThrowable());
}
}
<?php
/**
* Copyright (c) by the ACP3 Developers.
* See the LICENSE file at the top-level module directory for licensing details.
*/
namespace ACP3\Core\Application\Event;
use Symfony\Component\EventDispatcher\Event;
class OutputPageExceptionEvent extends Event
{
/**
* @var \Throwable
*/
private $throwable;
public function __construct(\Throwable $throwable)
{
$this->throwable = $throwable;
}
/**
* @return \Throwable
*/
public function getThrowable(): \Throwable
{
return $this->throwable;
}
}
......@@ -33,3 +33,10 @@ services:
- '@core.acl'
tags:
- { name: core.eventListener, event: core.application.controller_action_dispatcher.before_dispatch }
core.application.event.on_output_page_listener:
class: ACP3\Core\Application\Event\Listener\OnOutputPageExceptionListener
arguments:
- '@core.logger.system_logger'
tags:
- { name: core.eventListener, event: core.output_page_exception }
......@@ -13,4 +13,4 @@ services:
class: Psr\Log\LoggerInterface
factory: 'core.logger.logger_factory:create'
arguments:
- 'system'
- 'error'
......@@ -46,3 +46,4 @@ services:
core.event_dispatcher:
class: Symfony\Component\EventDispatcher\EventDispatcher
public: true
......@@ -8,6 +8,7 @@
namespace ACP3\Installer\Core\Application;
use ACP3\Core;
use ACP3\Core\Application\Event\OutputPageExceptionEvent;
use ACP3\Installer\Core\DependencyInjection\ServiceContainerBuilder;
use ACP3\Installer\Core\Environment\ApplicationPath;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
......@@ -57,7 +58,7 @@ class Bootstrap extends Core\Application\AbstractBootstrap
*/
public function initializeClasses(SymfonyRequest $symfonyRequest)
{
$this->container = ServiceContainerBuilder::create($this->logger, $this->appPath, $symfonyRequest, $this->appMode);
$this->container = ServiceContainerBuilder::create($this->appPath, $symfonyRequest, $this->appMode);
}
/**
......@@ -72,8 +73,11 @@ class Bootstrap extends Core\Application\AbstractBootstrap
$response = $controllerActionDispatcher->dispatch();
} catch (Core\Controller\Exception\ControllerActionNotFoundException $e) {
$response = $controllerActionDispatcher->dispatch('errors.controller.install.index.not_found');
} catch (\Exception $e) {
$this->logger->critical($e);
} catch (\Throwable $e) {
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher */
$eventDispatcher = $this->container->get('core.event_dispatcher');
$eventDispatcher->dispatch('core.output_page_exception', new OutputPageExceptionEvent($e));
$response = $controllerActionDispatcher->dispatch('errors.controller.install.index.server_error');
}
......
......@@ -16,7 +16,6 @@ use ACP3\Core\Validation\DependencyInjection\RegisterValidationRulesPass;
use ACP3\Core\View\Renderer\Smarty\DependencyInjection\RegisterLegacySmartyPluginsPass;
use ACP3\Core\View\Renderer\Smarty\DependencyInjection\RegisterSmartyPluginsPass;
use ACP3\Installer\Core\Environment\ApplicationPath;
use Psr\Log\LoggerInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
......@@ -25,10 +24,6 @@ use Symfony\Component\HttpFoundation\Request;
class ServiceContainerBuilder extends ContainerBuilder
{
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var ApplicationPath
*/
......@@ -49,7 +44,6 @@ class ServiceContainerBuilder extends ContainerBuilder
/**
* ServiceContainerBuilder constructor.
*
* @param LoggerInterface $logger
* @param ApplicationPath $applicationPath
* @param Request $symfonyRequest
* @param string $applicationMode
......@@ -58,7 +52,6 @@ class ServiceContainerBuilder extends ContainerBuilder
* @throws \Exception
*/
public function __construct(
LoggerInterface $logger,
ApplicationPath $applicationPath,
Request $symfonyRequest,
string $applicationMode,
......@@ -66,7 +59,6 @@ class ServiceContainerBuilder extends ContainerBuilder
) {
parent::__construct();
$this->logger = $logger;
$this->applicationPath = $applicationPath;
$this->symfonyRequest = $symfonyRequest;
$this->applicationMode = $applicationMode;
......@@ -83,7 +75,6 @@ class ServiceContainerBuilder extends ContainerBuilder
$this->setParameter('cache_driver', 'Array');
$this->set('core.http.symfony_request', $this->symfonyRequest);
$this->set('core.environment.application_path', $this->applicationPath);
$this->set('core.logger.system_logger', $this->logger);
$this
->addCompilerPass(
new RegisterListenersPass(
......@@ -171,7 +162,6 @@ class ServiceContainerBuilder extends ContainerBuilder
}
/**
* @param LoggerInterface $logger
* @param ApplicationPath $applicationPath
* @param Request $symfonyRequest
* @param string $applicationMode
......@@ -182,12 +172,11 @@ class ServiceContainerBuilder extends ContainerBuilder
* @throws \Exception
*/
public static function create(
LoggerInterface $logger,
ApplicationPath $applicationPath,
Request $symfonyRequest,
string $applicationMode,
bool $includeModules = false
) {
return new static($logger, $applicationPath, $symfonyRequest, $applicationMode, $includeModules);
return new static($applicationPath, $symfonyRequest, $applicationMode, $includeModules);
}
}
......@@ -30,3 +30,9 @@ services:
tags:
- { name: core.eventListener, event: core.application.controller_action_dispatcher.before_dispatch }
core.application.event.on_output_page_listener:
class: ACP3\Core\Application\Event\Listener\OnOutputPageExceptionListener
arguments:
- '@core.logger.system_logger'
tags:
- { name: core.eventListener, event: core.output_page_exception }
services:
core.logger:
class: ACP3\Core\Logger
arguments:
- '@core.environment.application_path'
core.logger.logger_factory:
class: ACP3\Core\Logger\LoggerFactory
arguments:
- '@core.environment.application_path'
core.logger.system_logger:
class: Psr\Log\LoggerInterface
factory: 'core.logger.logger_factory:create'
arguments:
- 'error'
......@@ -17,11 +17,6 @@ services:
arguments:
- '@core.environment.application_path'
core.logger:
class: ACP3\Core\Logger
arguments:
- '@core.environment.application_path'
core.router:
class: ACP3\Installer\Core\Router\Router
arguments:
......@@ -59,6 +54,7 @@ services:
core.event_dispatcher:
class: Symfony\Component\EventDispatcher\EventDispatcher
public: true
core.xml:
class: ACP3\Core\XML
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment