You are here

class HudtException in Hook Update Deploy Tools 8

Same name and namespace in other branches
  1. 7 src/HudtException.php \HookUpdateDeployTools\HudtException

Public method for importing Rules.

Hierarchy

  • class \HookUpdateDeployTools\HudtException extends \HookUpdateDeployTools\DrupalUpdateException

Expanded class hierarchy of HudtException

File

src/HudtException.php, line 8

Namespace

HookUpdateDeployTools
View source
class HudtException extends \DrupalUpdateException {
  public $watchdogMessage;
  public $vars = array();
  public $watchdogCode;
  public $logIt;

  /**
   * Exception with optional watchdog logging on calling $e->logMessage().
   *
   * @param string $watchdog_message
   *   Message ready for sending to t().
   * @param array $vars
   *   Variables for use in string replacement in t().
   * @param int $watchdog_code
   *   Watchdog error codes for proper watchdog logging.
   * @param bool $log_it
   *   TRUE (default) to make a watchdog entry when $e->logMessage() is called.
   *   FALSE prevents watchdog entry when $e->logMessage() is called.
   */
  public function __construct($watchdog_message, $vars, $watchdog_code, $log_it = TRUE) {
    $t = get_t();

    // Assign properties from params.
    $this->watchdogMessage = $watchdog_message;
    $this->vars = (array) $vars;
    $this->watchdogCode = $watchdog_code;
    $this->logIt = !empty($log_it) ? TRUE : FALSE;
    $this->message = $t($watchdog_message, $vars);
  }

  /**
   * Logs the message to Watchdog.
   *
   * @param string $pre
   *   A string to prepend to the message.
   * @param string $post
   *   A string to append to the message.
   *
   * @return string
   *   The return from Message::make() or getMessage() if logging was skipped.
   */
  public function logMessage($pre = '', $post = '') {
    if ($this->logIt) {

      // Log it to watchdog.
      $full_message = "{$pre}{$this->watchdogMessage}{$post}";
      return Message::make($full_message, $this->vars, $this->watchdogCode, 1);
    }
    return $this
      ->getMessage();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HudtException::$logIt public property
HudtException::$vars public property
HudtException::$watchdogCode public property
HudtException::$watchdogMessage public property
HudtException::logMessage public function Logs the message to Watchdog.
HudtException::__construct public function Exception with optional watchdog logging on calling $e->logMessage().