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

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. namespace Fresh\DoctrineEnumBundle;
  11. use Doctrine\Common\Persistence\ConnectionRegistry;
  12. use Fresh\DoctrineEnumBundle\Exception\InvalidArgumentException;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. use Symfony\Component\HttpKernel\Bundle\Bundle;
  15. /**
  16.  * FreshDoctrineEnumBundle.
  17.  *
  18.  * @author Artem Henvald <genvaldartem@gmail.com>
  19.  */
  20. class FreshDoctrineEnumBundle extends Bundle
  21. {
  22.     /**
  23.      * {@inheritdoc}
  24.      *
  25.      * @throws InvalidArgumentException
  26.      * @throws \Doctrine\DBAL\DBALException
  27.      * @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
  28.      * @throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
  29.      */
  30.     public function boot(): void
  31.     {
  32.         parent::boot();
  33.         $doctrine $this->container->get('doctrine'ContainerInterface::NULL_ON_INVALID_REFERENCE);
  34.         if (!$doctrine instanceof ConnectionRegistry) {
  35.             throw new InvalidArgumentException('Service "doctrine" is missed in container');
  36.         }
  37.         /** @var \Doctrine\DBAL\Connection $connection */
  38.         foreach ($doctrine->getConnections() as $connection) {
  39.             /** @var \Doctrine\DBAL\Platforms\AbstractPlatform $databasePlatform */
  40.             $databasePlatform $connection->getDatabasePlatform();
  41.             if (!$databasePlatform->hasDoctrineTypeMappingFor('enum') || 'string' !== $databasePlatform->getDoctrineTypeMapping('enum')) {
  42.                 $databasePlatform->registerDoctrineTypeMapping('enum''string');
  43.             }
  44.         }
  45.     }
  46. }