You are here

protected function Dbug::getVariableName in dBug for Drupal 8

Same name and namespace in other branches
  1. 2.0.x src/Dbug.php \Drupal\dbug\Dbug::getVariableName()
  2. 1.0.x src/Dbug.php \Drupal\dbug\Dbug::getVariableName()

Get the variable name.

Return value

string The variable name.

1 call to Dbug::getVariableName()
Dbug::makeTableHeader in src/Dbug.php
Create the main table header.

File

src/Dbug.php, line 215

Class

Dbug
Implementation of dBug for Drupal.

Namespace

Drupal\dbug

Code

protected function getVariableName() {
  $arrBacktrace = debug_backtrace();

  // Possible 'included' functions.
  $arrInclude = [
    "include",
    "include_once",
    "require",
    "require_once",
  ];

  // Check for any included/required files. if found, get array of the last
  // included file (they contain the right line numbers).
  for ($i = count($arrBacktrace) - 1; $i >= 0; $i--) {
    $arrCurrent = $arrBacktrace[$i];
    if (array_key_exists("function", $arrCurrent) && (in_array($arrCurrent["function"], $arrInclude) || 0 != strcasecmp($arrCurrent["function"], "dbug"))) {
      continue;
    }
    $arrFile = $arrCurrent;
    break;
  }
  if (isset($arrFile)) {
    $arrLines = file($arrFile["file"]);
    $code = $arrLines[$arrFile["line"] - 1];

    // Find call to dBug class.
    preg_match('/\\bnew dBug\\s*\\(\\s*(.+)\\s*\\);/i', $code, $arrMatches);
    return $arrMatches[1];
  }
  return "";
}