src/Doctrine/Platform/CustomMySQL57Platform.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Doctrine\Platform;
  3. use Doctrine\DBAL\Platforms\MySQL57Platform;
  4. /**
  5.  * Custom platform class extending MySQL57Platform to handle ENUM types.
  6.  */
  7. class CustomMySQL57Platform extends MySQL57Platform
  8. {
  9.     /**
  10.      * Overrides the default Doctrine type mapping to handle ENUM types.
  11.      *
  12.      * Doctrine does not natively support ENUM types in MySQL.
  13.      * This method ensures that ENUM types are treated as strings in Doctrine's internal mapping.
  14.      *
  15.      * @param string $dbType The database type (e.g., 'enum').
  16.      * @return string The Doctrine type mapped from the database type.
  17.      */
  18.     public function getDoctrineTypeMapping($dbType)
  19.     {
  20.         // Check if the database type is 'enum'
  21.         if ($dbType === 'enum') {
  22.             // Map 'enum' database type to Doctrine's 'string' type for compatibility
  23.             return 'string';
  24.         }
  25.         // For all other types, use the default Doctrine mapping
  26.         return parent::getDoctrineTypeMapping($dbType);
  27.     }
  28. }