You are here

public function Connection::GetCallstackAsComment in Drupal driver for SQL Server and SQL Azure 8.2

Get the current callstack as a comment that can be appended to a query.

Parameters

string $application_root: Application root to remove from the callstack dump.

array $extras: Any application specific information that needs to be dumped.

Return value

string

File

drivers/lib/Drupal/Driver/Database/sqlsrv/PDO/Connection.php, line 258

Class

Connection

Namespace

Drupal\Driver\Database\sqlsrv\PDO

Code

public function GetCallstackAsComment($application_root, array $extras = array()) {
  $trim = strlen($application_root);
  $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

  // Remove last items.
  $trace = array_splice($trace, 2);
  $comment = PHP_EOL . PHP_EOL;
  foreach ($extras as $extra) {
    $comment .= $extra . PHP_EOL;
  }
  $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'none';
  $uri = preg_replace("/[^a-zA-Z0-9]/i", "_", $uri);
  $comment .= '-- url:' . $uri . PHP_EOL;
  foreach ($trace as $t) {
    $function = isset($t['function']) ? $t['function'] : '';
    $file = '';
    if (isset($t['file'])) {
      $len = strlen($t['file']);
      if ($len > $trim) {
        $file = substr($t['file'], $trim, $len - $trim) . " [{$t['line']}]";
      }
    }
    $comment .= '-- ' . str_pad($function, 35) . '  ' . $file . PHP_EOL;
  }
  $comment .= PHP_EOL;
  return $comment;
}