Ejemplo n.º 1
0
 /**
  * Saves exception in class.
  *
  * @param mixed $e Exception
  */
 protected static function setException($e)
 {
     Log::error($e);
     static::$exception = $e;
 }
 /**
  * Handles all PHP exceptions.
  *
  * @param exception|\exception $exception An exception.
  *
  * @note Exceptions handled successfully by this routine will NOT be logged by PHP as errors.
  *    As the exception handler, we will need to log and/or display anything that needs to be recorded here.
  *    The PHP interpreter simply terminates script execution whenever an exception occurs (nothing more).
  *
  * @note If an exception is thrown while handling an exception; PHP will revert to it's default exception handler.
  *    This will result in a fatal error that may get logged by PHP itself (depending on `error_reporting` and `error_log`).
  *
  * @throws exception|\exception If we are unable to handle the exception (i.e. the XDaRk Core is not even available yet),
  *    this handler will simply re-throw the exception (forcing a fatal error); as just described in the previous note.
  *
  * @note The display of exception messages is NOT dependent upon `display_errors`; nor do we consider that setting here.
  *    However, we do tighten security within the `exception.php` template file; hiding most details by default; and displaying all details
  *    only if the current user is a Super Administrator in WordPress; or if `WP_DEBUG_DISPLAY` mode has been enabled on this site.
  *
  * @note If there was another exception handler active on the site; and this exception is NOT for
  *    a plugin under this version of the XDaRk Core; we simply hand the exception back to the previous handler.
  *    In the case of multiple versions of the XDaRk Core across various plugins; this allows us to work up the chain
  *    of previous handlers until we find the right version of the XDaRk Core; assuming each version
  *    of the XDaRk Core handles things this way too (which is to be expected).
  *
  * @see http://php.net/manual/en/function.set-exception-handler.php
  */
 public static function handle(\exception $exception)
 {
     try {
         static::$exception = $exception;
         // Reference.
         if (static::$exception instanceof exception) {
             static::$plugin = static::$exception->plugin;
             static::handle_plugin_exception();
             return;
             // We're done here.
         }
         // Else this is some other type of exception.
         if (static::$previous_handler && is_callable(static::$previous_handler)) {
             call_user_func(static::$previous_handler, static::$exception);
             return;
             // We're done here.
         }
         // There is NO other handler available (deal w/ it here; if possible).
         if (is_callable('\\' . stub::$core_ns . '\\core')) {
             static::$plugin = core();
             static::handle_plugin_exception();
             return;
             // We're done here.
         }
         throw static::$exception;
         // Re-throw (forcing a fatal error).
     } catch (\exception $_exception) {
         throw new \exception(sprintf(stub::__('Failed to handle exception code: `%1$s` with message: `%2$s`.'), $exception->getCode(), $exception->getMessage()) . ' ' . sprintf(stub::__('Failure caused by exception code: `%1$s` with message: `%2$s`.'), $_exception->getCode(), $_exception->getMessage()), 20, $_exception);
     }
 }