[ Index ]

PHP Cross Reference of phpBB-3.3.5-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\ConsoleErrorEvent;
  19  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  20  
  21  class exception_subscriber implements EventSubscriberInterface
  22  {
  23      /** @var \phpbb\language\language */
  24      protected $language;
  25  
  26      /**
  27       * Constructor.
  28       *
  29       * @param \phpbb\language\language    $language    Language object
  30       */
  31  	public function __construct(\phpbb\language\language $language)
  32      {
  33          $this->language = $language;
  34      }
  35  
  36      /**
  37       * This listener is run when the ConsoleEvents::ERROR event is triggered.
  38       * It translate the error message. If in debug mode the original exception is embedded.
  39       *
  40       * @param ConsoleErrorEvent $event
  41       */
  42  	public function on_error(ConsoleErrorEvent $event)
  43      {
  44          $original_exception = $event->getError();
  45  
  46          if ($original_exception instanceof exception_interface)
  47          {
  48              $parameters = array_merge([$original_exception->getMessage()], $original_exception->get_parameters());
  49              $message = call_user_func_array([$this->language, 'lang'], $parameters);
  50  
  51              $exception = new \RuntimeException($message , $original_exception->getCode(), $original_exception);
  52  
  53              $event->setError($exception);
  54          }
  55      }
  56  
  57  	static public function getSubscribedEvents()
  58      {
  59          return [
  60              ConsoleEvents::ERROR => 'on_error',
  61          ];
  62      }
  63  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1