removeDatabaseEntriesFromDebugBacktrace example


  public static function removeDatabaseEntries(array $backtrace, string $driver_namespace): array {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use Connection::removeDatabaseEntriesFromDebugBacktrace(). See https://www.drupal.org/node/3328053', E_USER_DEPRECATED);
    return Connection::removeDatabaseEntriesFromDebugBacktrace($backtrace$driver_namespace);
  }

  /** * Gets the debug backtrace. * * Wraps the debug_backtrace function to allow mocking results in PHPUnit * tests. * * @return array[] * The debug backtrace. * * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is * no replacement. * * @see https://www.drupal.org/node/3328053 */

  public function findCallerFromDebugBacktrace(): array {
    $stack = $this->removeDatabaseEntriesFromDebugBacktrace($this->getDebugBacktrace()$this->getConnectionOptions()['namespace']);
    // Return the first function call whose stack entry has a 'file' key, that     // is, it is not a callback or a closure.     for ($i = 0; $i < count($stack)$i++) {
      if (!empty($stack[$i]['file'])) {
        return [
          'file' => $stack[$i]['file'],
          'line' => $stack[$i]['line'],
          'function' => $stack[$i + 1]['function'],
          'class' => $stack[$i + 1]['class'] ?? NULL,
          'type' => $stack[$i + 1]['type'] ?? NULL,
          'args' => $stack[$i + 1]['args'] ?? [],
        ];
public static function decodeException($exception) {
    $message = $exception->getMessage();

    $backtrace = $exception->getTrace();
    // Add the line throwing the exception to the backtrace.     array_unshift($backtrace['line' => $exception->getLine(), 'file' => $exception->getFile()]);

    // For PDOException errors, we try to return the initial caller,     // skipping internal functions of the database layer.     if ($exception instanceof \PDOException || $exception instanceof DatabaseExceptionWrapper) {
      $driver_namespace = Database::getConnectionInfo()['default']['namespace'];
      $backtrace = Connection::removeDatabaseEntriesFromDebugBacktrace($backtrace$driver_namespace);
      if (isset($exception->query_string, $exception->args)) {
        $message .= ": " . $exception->query_string . "; " . print_r($exception->args, TRUE);
      }
    }

    $caller = static::getLastCaller($backtrace);

    return [
      '%type' => get_class($exception),
      // The standard PHP exception handler considers that the exception message       // is plain-text. We mimic this behavior here.
Home | Imprint | This part of the site doesn't use cookies.