Skip to content

Commit

Permalink
Copy internal SQLResultCasing from ORM
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed May 19, 2022
1 parent 9bc477f commit e7f3361
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AuditReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Internal\SQLResultCasing;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\QuoteStrategy;
use Doctrine\ORM\ORMException;
Expand All @@ -31,6 +30,7 @@
use SimpleThings\EntityAudit\Exception\NotAuditedException;
use SimpleThings\EntityAudit\Metadata\MetadataFactory;
use SimpleThings\EntityAudit\Utils\ArrayDiff;
use SimpleThings\EntityAudit\Utils\SQLResultCasing;

/**
* @phpstan-template T of object
Expand Down
46 changes: 46 additions & 0 deletions src/Utils/SQLResultCasing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SimpleThings\EntityAudit\Utils;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;

/**
* This trait is a copy of \Doctrine\ORM\Internal\SQLResultCasing.
*
* @see https://github.com/doctrine/orm/blob/8f7701279de84411020304f668cc8b49a5afbf5a/lib/Doctrine/ORM/Internal/SQLResultCasing.php
*
* @internal
*/
trait SQLResultCasing
{
private function getSQLResultCasing(AbstractPlatform $platform, string $column): string
{
if ($platform instanceof DB2Platform || $platform instanceof OraclePlatform) {
return \strtoupper($column);
}

if ($platform instanceof PostgreSQLPlatform) {
return \strtolower($column);
}

if (\method_exists($platform, 'getSQLResultCasing')) {
return $platform->getSQLResultCasing($column);
}

return $column;
}
}

0 comments on commit e7f3361

Please sign in to comment.