Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PdoCaster.php

function PdoCaster::castPdo

File

vendor/symfony/var-dumper/Caster/PdoCaster.php, line 62

Class

PdoCaster
Casts PDO related classes to array representation.

Namespace

Symfony\Component\VarDumper\Caster

Code

public static function castPdo(\PDO $c, array $a, Stub $stub, bool $isNested) : array {
    $attr = [];
    $errmode = $c->getAttribute(\PDO::ATTR_ERRMODE);
    $c->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
    foreach (self::PDO_ATTRIBUTES as $k => $v) {
        if (!isset($k[0])) {
            $k = $v;
            $v = [];
        }
        try {
            $attr[$k] = 'ERRMODE' === $k ? $errmode : $c->getAttribute(\constant('PDO::ATTR_' . $k));
            if ($v && isset($v[$attr[$k]])) {
                $attr[$k] = new ConstStub($v[$attr[$k]], $attr[$k]);
            }
        } catch (\Exception) {
        }
    }
    if (isset($attr[$k = 'STATEMENT_CLASS'][1])) {
        if ($attr[$k][1]) {
            $attr[$k][1] = new ArgsStub($attr[$k][1], '__construct', $attr[$k][0]);
        }
        $attr[$k][0] = new ClassStub($attr[$k][0]);
    }
    $prefix = Caster::PREFIX_VIRTUAL;
    $a += [
        $prefix . 'inTransaction' => method_exists($c, 'inTransaction'),
        $prefix . 'errorInfo' => $c->errorInfo(),
        $prefix . 'attributes' => new EnumStub($attr),
    ];
    if ($a[$prefix . 'inTransaction']) {
        $a[$prefix . 'inTransaction'] = $c->inTransaction();
    }
    else {
        unset($a[$prefix . 'inTransaction']);
    }
    if (!isset($a[$prefix . 'errorInfo'][1], $a[$prefix . 'errorInfo'][2])) {
        unset($a[$prefix . 'errorInfo']);
    }
    $c->setAttribute(\PDO::ATTR_ERRMODE, $errmode);
    return $a;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal