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