8000 add CompilerPass for register UidTypes · symfony/symfony@ffc49ae · GitHub
[go: up one dir, main page]

Skip to content

Commit ffc49ae

Browse files
author
Gennadi Janzen
committed
add CompilerPass for register UidTypes
uuid and ulid will only be register if there are not set
1 parent 8112bdc commit ffc49ae

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass;
13+
14+
use Symfony\Bridge\Doctrine\Types\UlidType;
15+
use Symfony\Bridge\Doctrine\Types\UuidType;
16+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\Uid\AbstractUid;
19+
20+
/ D25D **
21+
* Registers additional validators.
22+
*
23+
* @author Benjamin Eberlei <kontakt@beberlei.de>
24+
*/
25+
class RegisterUidTypePass implements CompilerPassInterface
26+
{
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function process(ContainerBuilder $container)
31+
{
32+
if (!class_exists(AbstractUid::class)) {
33+
return;
34+
}
35+
36+
$typeDefinition = $container->getParameter('doctrine.dbal.connection_factory.types');
37+
38+
if (!isset($typeDefinition['uuid'])) {
39+
$typeDefinition['uuid'] = ['class' => UuidType::class];
40+
}
41+
42+
if (!isset($typeDefinition['ulid'])) {
43+
$typeDefinition['ulid'] = ['class' => UlidType::class];
44+
}
45+
46+
$container->setParameter('doctrine.dbal.connection_factory.types', $typeDefinition);
47+
}
48+
}

0 commit comments

Comments
 (0)
0