function Connection::removeDatabaseEntriesFromDebugBacktrace

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::removeDatabaseEntriesFromDebugBacktrace()

Removes database related calls from a backtrace array.

Parameters

array $backtrace: A standard PHP backtrace. Passed by reference.

string $driver_namespace: The PHP namespace of the database driver.

Return value

array The cleaned backtrace array.

3 calls to Connection::removeDatabaseEntriesFromDebugBacktrace()
Connection::findCallerFromDebugBacktrace in core/lib/Drupal/Core/Database/Connection.php
Determine the last non-database method that called the database API.
Error::decodeException in core/lib/Drupal/Core/Utility/Error.php
Decodes an exception and retrieves the correct caller.
Log::removeDatabaseEntries in core/lib/Drupal/Core/Database/Log.php
Removes database related calls from a backtrace array.

File

core/lib/Drupal/Core/Database/Connection.php, line 2207

Class

Connection
Base Database API class.

Namespace

Drupal\Core\Database

Code

public static function removeDatabaseEntriesFromDebugBacktrace(array $backtrace, string $driver_namespace) : array {
    // Starting from the very first entry processed during the request, find
    // the first function call that can be identified as a call to a
    // method/function in the database layer.
    for ($n = count($backtrace) - 1; $n >= 0; $n--) {
        // If the call was made from a function, 'class' will be empty. We give
        // it a default empty string value in that case.
        $class = $backtrace[$n]['class'] ?? '';
        if (str_starts_with($class, __NAMESPACE__) || str_starts_with($class, $driver_namespace)) {
            break;
        }
    }
    return array_values(array_slice($backtrace, $n));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.