[ Index ]

PHP Cross Reference of phpBB-3.3.0-deutsch

title

Body

[close]

/phpbb/console/ -> exception_subscriber.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\console;
  15  
  16  use phpbb\exception\exception_interface;
  17  use Symfony\Component\Console\ConsoleEvents;
  18  use Symfony\Component\Console\Event\ConsoleExceptionEvent;
  19  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  20  
  21  class exception_subscriber implements EventSubscriberInterface
  22  {
  23      /**
  24       * @var \phpbb\language\language
  25       */
  26      protected $language;
  27  
  28      /**
  29       * Construct method
  30       *
  31       * @param \phpbb\language\language $language Language object
  32       */
  33  	public function __construct(\phpbb\language\language $language)
  34      {
  35          $this->language = $language;
  36      }
  37  
  38      /**
  39       * This listener is run when the ConsoleEvents::EXCEPTION event is triggered.
  40       * It translate the exception message. If din debug mode the original exception is embedded.
  41       *
  42       * @param ConsoleExceptionEvent $event
  43       */
  44  	public function on_exception(ConsoleExceptionEvent $event)
  45      {
  46          $original_exception = $event->getException();
  47  
  48          if ($original_exception instanceof exception_interface)
  49          {
  50              $parameters = array_merge(array($original_exception->getMessage()), $original_exception->get_parameters());
  51              $message = call_user_func_array(array($this->language, 'lang'), $parameters);
  52  
  53              $exception = new \RuntimeException($message , $original_exception->getCode(), $original_exception);
  54  
  55              $event->setException($exception);
  56          }
  57      }
  58  
  59  	static public function getSubscribedEvents()
  60      {
  61          return array(
  62              ConsoleEvents::EXCEPTION => 'on_exception',
  63          );
  64      }
  65  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1