You are here

class Exception in Realistic Dummy Content 8

An \Exception.

Hierarchy

  • class \Drupal\realistic_dummy_content_api\loggers\Exception
    • class \Drupal\realistic_dummy_content_api\loggers\Exception

Expanded class hierarchy of Exception

6 files declare their use of Exception
Attribute.php in api/src/attributes/Attribute.php
Define autoload class.
EntityBase.php in api/src/manipulators/EntityBase.php
Define autoload class.
Environment.php in api/src/environments/Environment.php
Define autoload class.
FieldModifier.php in api/src/manipulators/FieldModifier.php
Define autoload class.
FileGroup.php in api/src/environments/FileGroup.php
Define autoload class.

... See full list

File

api/src/loggers/Exception.php, line 15
Define autoload class.

Namespace

Drupal\realistic_dummy_content_api\loggers
View source
class Exception extends \Exception {

  // When returning the caller of the function which resulted in the \Exception
  // we need to go 4 levels deep. When returning the called function, we also
  // need to 4 levels deep, but call GetCaller() through another function which adds
  // a level (GetCalled()).
  const REALISTIC_DUMMY_CONTENT_BACKTRACE_LEVEL = 4;
  function __construct($message) {
    parent::__construct($message);
    $this
      ->Log();
  }
  function Log() {
    $message = $this
      ->getMessage() . ' (' . $this
      ->GetCaller() . ' called ' . $this
      ->GetCalled() . ')';
    debug($message);
    if (\Drupal::moduleHandler()
      ->moduleExists('devel')) {
      dpm($message);
    }
  }

  /**
   * Returns the calling function through a backtrace
   */
  static function GetCaller() {

    // a funciton x has called a function y which called this
    // see stackoverflow.com/questions/190421
    $caller = debug_backtrace();
    $caller = $caller[Exception::REALISTIC_DUMMY_CONTENT_BACKTRACE_LEVEL];
    $r = $caller['function'] . '()';
    if (isset($caller['class'])) {
      $r .= ' in ' . $caller['class'];
    }
    if (isset($caller['object'])) {
      $r .= ' (' . get_class($caller['object']) . ')';
    }
    return $r;
  }

  /**
   * Returns the called function through a backtrace
   */
  static function GetCalled() {

    // Get caller will return the called function because the simple fact
    // of using another function will make the backtrace one-level deeper
    return self::GetCaller();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Exception::GetCalled static function Returns the called function through a backtrace Overrides Exception::GetCalled 1
Exception::GetCaller static function Returns the calling function through a backtrace Overrides Exception::GetCaller 1
Exception::Log function Overrides Exception::Log 1
Exception::REALISTIC_DUMMY_CONTENT_BACKTRACE_LEVEL constant Overrides Exception::REALISTIC_DUMMY_CONTENT_BACKTRACE_LEVEL 1
Exception::__construct function Overrides Exception::__construct 1