vendor/fresh/doctrine-enum-bundle/FreshDoctrineEnumBundle.php line 25

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FreshDoctrineEnumBundle.
  4.  *
  5.  * (c) Artem Henvald <genvaldartem@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Fresh\DoctrineEnumBundle;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. use Fresh\DoctrineEnumBundle\Exception\InvalidArgumentException;
  14. use Symfony\Component\DependencyInjection\ContainerInterface;
  15. use Symfony\Component\HttpKernel\Bundle\Bundle;
  16. /**
  17.  * FreshDoctrineEnumBundle.
  18.  *
  19.  * @author Artem Henvald <genvaldartem@gmail.com>
  20.  */
  21. class FreshDoctrineEnumBundle extends Bundle
  22. {
  23.     /**
  24.      * {@inheritdoc}
  25.      *
  26.      * @throws InvalidArgumentException
  27.      * @throws \Doctrine\DBAL\DBALException
  28.      * @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
  29.      * @throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
  30.      */
  31.     public function boot(): void
  32.     {
  33.         parent::boot();
  34.         $doctrine $this->container->get('doctrine'ContainerInterface::NULL_ON_INVALID_REFERENCE);
  35.         if (!$doctrine instanceof ManagerRegistry) {
  36.             throw new InvalidArgumentException('Service "doctrine" is missed in container');
  37.         }
  38.         /** @var \Doctrine\DBAL\Connection $connection */
  39.         foreach ($doctrine->getConnections() as $connection) {
  40.             /** @var \Doctrine\DBAL\Platforms\AbstractPlatform $databasePlatform */
  41.             $databasePlatform $connection->getDatabasePlatform();
  42.             if (!$databasePlatform->hasDoctrineTypeMappingFor('enum') || 'string' !== $databasePlatform->getDoctrineTypeMapping('enum')) {
  43.                 $databasePlatform->registerDoctrineTypeMapping('enum''string');
  44.             }
  45.         }
  46.     }
  47. }