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; ...@@ -9,8 +9,6 @@ namespace ACP3\Core\Application;
use ACP3\Core\Environment\ApplicationMode; use ACP3\Core\Environment\ApplicationMode;
use ACP3\Core\Environment\ApplicationPath; use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Logger\LoggerFactory;
use Psr\Log\LoggerInterface;
use Symfony\Component\Debug\ErrorHandler; use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler; use Symfony\Component\Debug\ExceptionHandler;
...@@ -28,10 +26,6 @@ abstract class AbstractBootstrap implements BootstrapInterface ...@@ -28,10 +26,6 @@ abstract class AbstractBootstrap implements BootstrapInterface
* @var \ACP3\Core\Environment\ApplicationPath * @var \ACP3\Core\Environment\ApplicationPath
*/ */
protected $appPath; protected $appPath;
/**
* @var LoggerInterface
*/
protected $logger;
/** /**
* @param string $appMode * @param string $appMode
...@@ -42,7 +36,6 @@ abstract class AbstractBootstrap implements BootstrapInterface ...@@ -42,7 +36,6 @@ abstract class AbstractBootstrap implements BootstrapInterface
{ {
$this->appMode = $appMode; $this->appMode = $appMode;
$this->initializeApplicationPath(); $this->initializeApplicationPath();
$this->logger = (new LoggerFactory($this->appPath))->create('error');
} }
protected function initializeApplicationPath() protected function initializeApplicationPath()
...@@ -60,7 +53,6 @@ abstract class AbstractBootstrap implements BootstrapInterface ...@@ -60,7 +53,6 @@ abstract class AbstractBootstrap implements BootstrapInterface
ExceptionHandler::register($debug); ExceptionHandler::register($debug);
$errorHandler = new ErrorHandler(); $errorHandler = new ErrorHandler();
$errorHandler->setDefaultLogger($this->logger);
ErrorHandler::register($errorHandler); ErrorHandler::register($errorHandler);
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace ACP3\Core\Application; namespace ACP3\Core\Application;
use ACP3\Core\Application\Event\OutputPageExceptionEvent;
use ACP3\Core\Application\Exception\MaintenanceModeActiveException; use ACP3\Core\Application\Exception\MaintenanceModeActiveException;
use ACP3\Core\Controller\Exception\ForwardControllerActionAwareExceptionInterface; use ACP3\Core\Controller\Exception\ForwardControllerActionAwareExceptionInterface;
use ACP3\Core\DependencyInjection\ServiceContainerBuilder; use ACP3\Core\DependencyInjection\ServiceContainerBuilder;
...@@ -84,7 +85,7 @@ class Bootstrap extends AbstractBootstrap ...@@ -84,7 +85,7 @@ class Bootstrap extends AbstractBootstrap
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @throws \Exception * @throws \Throwable
*/ */
public function outputPage() public function outputPage()
{ {
...@@ -104,8 +105,11 @@ class Bootstrap extends AbstractBootstrap ...@@ -104,8 +105,11 @@ class Bootstrap extends AbstractBootstrap
$response = $controllerActionDispatcher->dispatch($e->getServiceId(), $e->routeParams()); $response = $controllerActionDispatcher->dispatch($e->getServiceId(), $e->routeParams());
} catch (MaintenanceModeActiveException $e) { } catch (MaintenanceModeActiveException $e) {
$response = new Response($e->getMessage(), $e->getCode()); $response = new Response($e->getMessage(), $e->getCode());
} catch (\Exception $e) { } catch (\Throwable $e) {
$this->logger->critical($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; 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: ...@@ -33,3 +33,10 @@ services:
- '@core.acl' - '@core.acl'
tags: tags:
- { name: core.eventListener, event: core.application.controller_action_dispatcher.before_dispatch } - { 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: ...@@ -13,4 +13,4 @@ services:
class: Psr\Log\LoggerInterface class: Psr\Log\LoggerInterface
factory: 'core.logger.logger_factory:create' factory: 'core.logger.logger_factory:create'
arguments: arguments:
- 'system' - 'error'
...@@ -46,3 +46,4 @@ services: ...@@ -46,3 +46,4 @@ services:
core.event_dispatcher: core.event_dispatcher:
class: Symfony\Component\EventDispatcher\EventDispatcher class: Symfony\Component\EventDispatcher\EventDispatcher
public: true
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace ACP3\Installer\Core\Application; namespace ACP3\Installer\Core\Application;
use ACP3\Core; use ACP3\Core;
use ACP3\Core\Application\Event\OutputPageExceptionEvent;
use ACP3\Installer\Core\DependencyInjection\ServiceContainerBuilder; use ACP3\Installer\Core\DependencyInjection\ServiceContainerBuilder;
use ACP3\Installer\Core\Environment\ApplicationPath; use ACP3\Installer\Core\Environment\ApplicationPath;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
...@@ -57,7 +58,7 @@ class Bootstrap extends Core\Application\AbstractBootstrap ...@@ -57,7 +58,7 @@ class Bootstrap extends Core\Application\AbstractBootstrap
*/ */
public function initializeClasses(SymfonyRequest $symfonyRequest) 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 ...@@ -72,8 +73,11 @@ class Bootstrap extends Core\Application\AbstractBootstrap
$response = $controllerActionDispatcher->dispatch(); $response = $controllerActionDispatcher->dispatch();
} catch (Core\Controller\Exception\ControllerActionNotFoundException $e) { } catch (Core\Controller\Exception\ControllerActionNotFoundException $e) {
$response = $controllerActionDispatcher->dispatch('errors.controller.install.index.not_found'); $response = $controllerActionDispatcher->dispatch('errors.controller.install.index.not_found');
} catch (\Exception $e) { } catch (\Throwable $e) {
$this->logger->critical($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'); $response = $controllerActionDispatcher->dispatch('errors.controller.install.index.server_error');
} }
......
...@@ -16,7 +16,6 @@ use ACP3\Core\Validation\DependencyInjection\RegisterValidationRulesPass; ...@@ -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\RegisterLegacySmartyPluginsPass;
use ACP3\Core\View\Renderer\Smarty\DependencyInjection\RegisterSmartyPluginsPass; use ACP3\Core\View\Renderer\Smarty\DependencyInjection\RegisterSmartyPluginsPass;
use ACP3\Installer\Core\Environment\ApplicationPath; use ACP3\Installer\Core\Environment\ApplicationPath;
use Psr\Log\LoggerInterface;
use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
...@@ -25,10 +24,6 @@ use Symfony\Component\HttpFoundation\Request; ...@@ -25,10 +24,6 @@ use Symfony\Component\HttpFoundation\Request;
class ServiceContainerBuilder extends ContainerBuilder class ServiceContainerBuilder extends ContainerBuilder
{ {
/**
* @var LoggerInterface
*/
private $logger;
/** /**
* @var ApplicationPath * @var ApplicationPath
*/ */
...@@ -49,7 +44,6 @@ class ServiceContainerBuilder extends ContainerBuilder ...@@ -49,7 +44,6 @@ class ServiceContainerBuilder extends ContainerBuilder
/** /**
* ServiceContainerBuilder constructor. * ServiceContainerBuilder constructor.
* *
* @param LoggerInterface $logger
* @param ApplicationPath $applicationPath * @param ApplicationPath $applicationPath
* @param Request $symfonyRequest * @param Request $symfonyRequest
* @param string $applicationMode * @param string $applicationMode
...@@ -58,7 +52,6 @@ class ServiceContainerBuilder extends ContainerBuilder ...@@ -58,7 +52,6 @@ class ServiceContainerBuilder extends ContainerBuilder
* @throws \Exception * @throws \Exception
*/ */
public function __construct( public function __construct(
LoggerInterface $logger,
ApplicationPath $applicationPath, ApplicationPath $applicationPath,
Request $symfonyRequest, Request $symfonyRequest,
string $applicationMode, string $applicationMode,
...@@ -66,7 +59,6 @@ class ServiceContainerBuilder extends ContainerBuilder ...@@ -66,7 +59,6 @@ class ServiceContainerBuilder extends ContainerBuilder
) { ) {
parent::__construct(); parent::__construct();
$this->logger = $logger;
$this->applicationPath = $applicationPath; $this->applicationPath = $applicationPath;
$this->symfonyRequest = $symfonyRequest; $this->symfonyRequest = $symfonyRequest;
$this->applicationMode = $applicationMode; $this->applicationMode = $applicationMode;
...@@ -83,7 +75,6 @@ class ServiceContainerBuilder extends ContainerBuilder ...@@ -83,7 +75,6 @@ class ServiceContainerBuilder extends ContainerBuilder
$this->setParameter('cache_driver', 'Array'); $this->setParameter('cache_driver', 'Array');
$this->set('core.http.symfony_request', $this->symfonyRequest); $this->set('core.http.symfony_request', $this->symfonyRequest);
$this->set('core.environment.application_path', $this->applicationPath); $this->set('core.environment.application_path', $this->applicationPath);
$this->set('core.logger.system_logger', $this->logger);
$this $this
->addCompilerPass( ->addCompilerPass(
new RegisterListenersPass( new RegisterListenersPass(
...@@ -171,7 +162,6 @@ class ServiceContainerBuilder extends ContainerBuilder ...@@ -171,7 +162,6 @@ class ServiceContainerBuilder extends ContainerBuilder
} }
/** /**
* @param LoggerInterface $logger
* @param ApplicationPath $applicationPath * @param ApplicationPath $applicationPath
* @param Request $symfonyRequest * @param Request $symfonyRequest
* @param string $applicationMode * @param string $applicationMode
...@@ -182,12 +172,11 @@ class ServiceContainerBuilder extends ContainerBuilder ...@@ -182,12 +172,11 @@ class ServiceContainerBuilder extends ContainerBuilder
* @throws \Exception * @throws \Exception
*/ */
public static function create( public static function create(
LoggerInterface $logger,
ApplicationPath $applicationPath, ApplicationPath $applicationPath,
Request $symfonyRequest, Request $symfonyRequest,
string $applicationMode, string $applicationMode,
bool $includeModules = false bool $includeModules = false
) { ) {
return new static($logger, $applicationPath, $symfonyRequest, $applicationMode, $includeModules); return new static($applicationPath, $symfonyRequest, $applicationMode, $includeModules);
} }
} }
...@@ -30,3 +30,9 @@ services: ...@@ -30,3 +30,9 @@ services:
tags: tags:
- { name: core.eventListener, event: core.application.controller_action_dispatcher.before_dispatch } - { 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: ...@@ -17,11 +17,6 @@ services:
arguments: arguments:
- '@core.environment.application_path' - '@core.environment.application_path'
core.logger:
class: ACP3\Core\Logger
arguments:
- '@core.environment.application_path'
core.router: core.router:
class: ACP3\Installer\Core\Router\Router class: ACP3\Installer\Core\Router\Router
arguments: arguments:
...@@ -59,6 +54,7 @@ services: ...@@ -59,6 +54,7 @@ services:
core.event_dispatcher: core.event_dispatcher:
class: Symfony\Component\EventDispatcher\EventDispatcher class: Symfony\Component\EventDispatcher\EventDispatcher
public: true
core.xml: core.xml:
class: ACP3\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