diff --git a/src/AuditReader.php b/src/AuditReader.php index 59e77fb6..4cd34927 100644 --- a/src/AuditReader.php +++ b/src/AuditReader.php @@ -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; @@ -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 diff --git a/src/Utils/SQLResultCasing.php b/src/Utils/SQLResultCasing.php new file mode 100644 index 00000000..fe137f15 --- /dev/null +++ b/src/Utils/SQLResultCasing.php @@ -0,0 +1,46 @@ + + * + * 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; + } +}