You are here

public static function Kint::dump in Devel 8

Same name and namespace in other branches
  1. 8.2 kint/kint/Kint.class.php \Kint::dump()

* Dump information about variables, accepts any number of parameters, supports modifiers: * * clean up any output before kint and place the dump at the top of page: * - Kint::dump() * ***** * expand all nodes on display: * ! Kint::dump() * ***** * dump variables disregarding their depth: * + Kint::dump() * ***** * return output instead of displaying it: * @ Kint::dump() * ***** * force output as plain text * ~ Kint::dump() * * Modifiers are supported by all dump wrapper functions, including Kint::trace(). Space is optional. * * * You can also use the following shorthand to display debug_backtrace(): * Kint::dump( 1 ); * * Passing the result from debug_backtrace() to kint::dump() as a single parameter will display it as trace too: * $trace = debug_backtrace( true ); * Kint::dump( $trace ); * Or simply: * Kint::dump( debug_backtrace() ); * * *

Parameters

mixed $data: * * @return void|string

5 calls to Kint::dump()
kint in kint/kint.module
Alias of Kint::dump().
Kint::export in kint/src/Plugin/Devel/Dumper/Kint.php
Returns a string representation of a variable.
Kint::trace in kint/kint/Kint.class.php
* Prints a debug backtrace, same as Kint::dump(1) * *
KintExtension::kint in kint/src/Twig/KintExtension.php
Provides Kint function to Twig templates.
ksm in kint/kint.module
Prints passed argument(s) to the 'message' area of the page.

File

kint/kint/Kint.class.php, line 155

Class

Kint

Code

public static function dump($data = null) {
  if (!self::enabled()) {
    return '';
  }
  list($names, $modifiers, $callee, $previousCaller, $miniTrace) = self::_getCalleeInfo(defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) : debug_backtrace());
  $modeOldValue = self::enabled();
  $firstRunOldValue = self::$_firstRun;

  # process modifiers: @, +, !, ~ and -
  if (strpos($modifiers, '-') !== false) {
    self::$_firstRun = true;
    while (ob_get_level()) {
      ob_end_clean();
    }
  }
  if (strpos($modifiers, '!') !== false) {
    $expandedByDefaultOldValue = self::$expandedByDefault;
    self::$expandedByDefault = true;
  }
  if (strpos($modifiers, '+') !== false) {
    $maxLevelsOldValue = self::$maxLevels;
    self::$maxLevels = false;
  }
  if (strpos($modifiers, '@') !== false) {
    $returnOldValue = self::$returnOutput;
    self::$returnOutput = true;
    self::$_firstRun = true;
  }
  if (strpos($modifiers, '~') !== false) {
    self::enabled(self::MODE_WHITESPACE);
  }

  # set mode for current run
  $mode = self::enabled();
  if ($mode === true) {
    $mode = PHP_SAPI === 'cli' ? self::MODE_CLI : self::MODE_RICH;
  }
  self::enabled($mode);
  $decorator = self::enabled() === self::MODE_RICH ? 'Kint_Decorators_Rich' : 'Kint_Decorators_Plain';
  $output = '';
  if (self::$_firstRun) {
    $output .= call_user_func(array(
      $decorator,
      'init',
    ));
  }
  $trace = false;
  if ($names === array(
    null,
  ) && func_num_args() === 1 && $data === 1) {

    # Kint::dump(1) shorthand
    $trace = KINT_PHP53 ? debug_backtrace(true) : debug_backtrace();
  }
  elseif (func_num_args() === 1 && is_array($data)) {
    $trace = $data;

    # test if the single parameter is result of debug_backtrace()
  }
  $trace and $trace = self::_parseTrace($trace);
  $output .= call_user_func(array(
    $decorator,
    'wrapStart',
  ));
  if ($trace) {
    $output .= call_user_func(array(
      $decorator,
      'decorateTrace',
    ), $trace);
  }
  else {
    $data = func_num_args() === 0 ? array(
      "[[no arguments passed]]",
    ) : func_get_args();
    foreach ($data as $k => $argument) {
      kintParser::reset();

      # when the dump arguments take long to generate output, user might have changed the file and

      # Kint might not parse the arguments correctly, so check if names are set and while the

      # displayed names might be wrong, at least don't throw an error
      $output .= call_user_func(array(
        $decorator,
        'decorate',
      ), kintParser::factory($argument, isset($names[$k]) ? $names[$k] : ''));
    }
  }
  $output .= call_user_func(array(
    $decorator,
    'wrapEnd',
  ), $callee, $miniTrace, $previousCaller);
  self::enabled($modeOldValue);
  self::$_firstRun = false;
  if (strpos($modifiers, '~') !== false) {
    self::$_firstRun = $firstRunOldValue;
  }
  else {
    self::enabled($modeOldValue);
  }
  if (strpos($modifiers, '!') !== false) {
    self::$expandedByDefault = $expandedByDefaultOldValue;
  }
  if (strpos($modifiers, '+') !== false) {
    self::$maxLevels = $maxLevelsOldValue;
  }
  if (strpos($modifiers, '@') !== false) {
    self::$returnOutput = $returnOldValue;
    self::$_firstRun = $firstRunOldValue;
    return $output;
  }
  if (self::$returnOutput) {
    return $output;
  }
  echo $output;
  return '';
}