[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/tobscure/json-api/src/ -> ErrorHandler.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of JSON-API.
   5   *
   6   * (c) Toby Zerner <[email protected]>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Tobscure\JsonApi;
  13  
  14  use Exception;
  15  use RuntimeException;
  16  use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
  17  
  18  class ErrorHandler
  19  {
  20      /**
  21       * Stores the valid handlers.
  22       *
  23       * @var \Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface[]
  24       */
  25      private $handlers = [];
  26  
  27      /**
  28       * Handle the exception provided.
  29       *
  30       * @param Exception $e
  31       *
  32       * @throws RuntimeException
  33       *
  34       * @return \Tobscure\JsonApi\Exception\Handler\ResponseBag
  35       */
  36      public function handle(Exception $e)
  37      {
  38          foreach ($this->handlers as $handler) {
  39              if ($handler->manages($e)) {
  40                  return $handler->handle($e);
  41              }
  42          }
  43  
  44          throw new RuntimeException('Exception handler for '.get_class($e).' not found.');
  45      }
  46  
  47      /**
  48       * Register a new exception handler.
  49       *
  50       * @param \Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface $handler
  51       *
  52       * @return void
  53       */
  54      public function registerHandler(ExceptionHandlerInterface $handler)
  55      {
  56          $this->handlers[] = $handler;
  57      }
  58  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer