OptimizeFlags.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\DBAL\Portability;
  4. use Doctrine\DBAL\Platforms\AbstractPlatform;
  5. use Doctrine\DBAL\Platforms\DB2Platform;
  6. use Doctrine\DBAL\Platforms\OraclePlatform;
  7. use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
  8. use Doctrine\DBAL\Platforms\SQLAnywhere16Platform;
  9. use Doctrine\DBAL\Platforms\SqlitePlatform;
  10. use Doctrine\DBAL\Platforms\SQLServer2012Platform;
  11. final class OptimizeFlags
  12. {
  13. /**
  14. * Platform-specific portability flags that need to be excluded from the user-provided mode
  15. * since the platform already operates in this mode to avoid unnecessary conversion overhead.
  16. *
  17. * @var array<string,int>
  18. */
  19. private static $platforms = [
  20. DB2Platform::class => 0,
  21. OraclePlatform::class => Connection::PORTABILITY_EMPTY_TO_NULL,
  22. PostgreSQL94Platform::class => 0,
  23. SQLAnywhere16Platform::class => 0,
  24. SqlitePlatform::class => 0,
  25. SQLServer2012Platform::class => 0,
  26. ];
  27. public function __invoke(AbstractPlatform $platform, int $flags): int
  28. {
  29. foreach (self::$platforms as $class => $mask) {
  30. if ($platform instanceof $class) {
  31. $flags &= ~$mask;
  32. break;
  33. }
  34. }
  35. return $flags;
  36. }
  37. }