Skip to content

Commit

Permalink
Compability: introduce simple doctrine version detector
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed May 9, 2022
1 parent a0eb236 commit e092aac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/Logger/ProfilerLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
use Doctrine\DBAL\SQLParserUtils;
use Doctrine\DBAL\Types\Type;
use Nettrine\DBAL\ConnectionAccessor;
use Nettrine\DBAL\Utils\Compatibility;
use Throwable;

class ProfilerLogger extends AbstractLogger
{

/** @var ?bool */
private $olderDbalVersion = null;

/** @var ConnectionAccessor */
protected $connectionAccessor;

Expand Down Expand Up @@ -80,11 +78,7 @@ public function startQuery($sql, ?array $params = null, ?array $types = null): v
*/
private function expandListParameters(string $query, array $params, array $types): array
{
if ($this->olderDbalVersion === null) {
$this->olderDbalVersion = class_exists(SQLParserUtils::class);
}

if ($this->olderDbalVersion) { // DBAL 2.x compatibility
if (Compatibility::isDoctrineV2()) { // DBAL 2.x compatibility
try {
return SQLParserUtils::expandListParameters($query, $params, $types); /** @phpstan-ignore-line */
} catch (Throwable $e) {
Expand Down
22 changes: 22 additions & 0 deletions src/Utils/Compatibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace Nettrine\DBAL\Utils;

use Doctrine\DBAL\SQLParserUtils;

final class Compatibility
{

/** @var bool|null */
public static $doctrine2 = null;

public static function isDoctrineV2(): bool
{
if (self::$doctrine2 === null) {
self::$doctrine2 = class_exists(SQLParserUtils::class);
}

return self::$doctrine2;
}

}

0 comments on commit e092aac

Please sign in to comment.