diff options
author | Maat <maat-pub@mageia.biz> | 2020-05-08 21:52:11 +0200 |
---|---|---|
committer | Maat <maat-pub@mageia.biz> | 2020-05-08 21:52:11 +0200 |
commit | 8ea437e30605e0f66b5220bf904a61d7c1d11ddd (patch) | |
tree | e0db2bb4a012d5b06a633160b19f62f4868ecd28 /phpBB/phpbb/console/exception_subscriber.php | |
parent | 36bc1870f21fac04736a1049c1d5b8e127d729f4 (diff) | |
parent | 2fdd46b36431ae0f58bb2e78e42553168db9a0ff (diff) | |
download | forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.gz forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.bz2 forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.xz forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.zip |
Merge remote-tracking branch 'upstream/prep-release-3.2.9'
Diffstat (limited to 'phpBB/phpbb/console/exception_subscriber.php')
-rw-r--r-- | phpBB/phpbb/console/exception_subscriber.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/phpBB/phpbb/console/exception_subscriber.php b/phpBB/phpbb/console/exception_subscriber.php new file mode 100644 index 0000000000..b240993203 --- /dev/null +++ b/phpBB/phpbb/console/exception_subscriber.php @@ -0,0 +1,65 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\console; + +use phpbb\exception\exception_interface; +use Symfony\Component\Console\ConsoleEvents; +use Symfony\Component\Console\Event\ConsoleExceptionEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +class exception_subscriber implements EventSubscriberInterface +{ + /** + * @var \phpbb\language\language + */ + protected $language; + + /** + * Construct method + * + * @param \phpbb\language\language $language Language object + */ + public function __construct(\phpbb\language\language $language) + { + $this->language = $language; + } + + /** + * This listener is run when the ConsoleEvents::EXCEPTION event is triggered. + * It translate the exception message. If din debug mode the original exception is embedded. + * + * @param ConsoleExceptionEvent $event + */ + public function on_exception(ConsoleExceptionEvent $event) + { + $original_exception = $event->getException(); + + if ($original_exception instanceof exception_interface) + { + $parameters = array_merge(array($original_exception->getMessage()), $original_exception->get_parameters()); + $message = call_user_func_array(array($this->language, 'lang'), $parameters); + + $exception = new \RuntimeException($message , $original_exception->getCode(), $original_exception); + + $event->setException($exception); + } + } + + static public function getSubscribedEvents() + { + return array( + ConsoleEvents::EXCEPTION => 'on_exception', + ); + } +} |