Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit 561a042

Browse files
committed
refactor(config): Migrate doctrine.yaml to PHP
1 parent afa271d commit 561a042

File tree

2 files changed

+116
-82
lines changed

2 files changed

+116
-82
lines changed

config/packages/doctrine.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Oro\ORM\Query\AST\Functions\Cast;
6+
use Oro\ORM\Query\AST\Functions\DateTime\ConvertTz;
7+
use Oro\ORM\Query\AST\Functions\Numeric\Pow;
8+
use Oro\ORM\Query\AST\Functions\Numeric\Round;
9+
use Oro\ORM\Query\AST\Functions\Numeric\Sign;
10+
use Oro\ORM\Query\AST\Functions\Numeric\TimestampDiff;
11+
use Oro\ORM\Query\AST\Functions\SimpleFunction;
12+
use Oro\ORM\Query\AST\Functions\String\ConcatWs;
13+
use Oro\ORM\Query\AST\Functions\String\DateFormat;
14+
use Oro\ORM\Query\AST\Functions\String\GroupConcat;
15+
use Oro\ORM\Query\AST\Functions\String\Replace;
16+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
17+
use Symfony\Config\DoctrineConfig;
18+
use Symfony\Config\FrameworkConfig;
19+
20+
use function Symfony\Component\DependencyInjection\Loader\Configurator\env;
21+
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
22+
23+
return static function (ContainerConfigurator $containerConfigurator, DoctrineConfig $doctrineConfig, FrameworkConfig $frameworkConfig): void {
24+
$dbalConfig = $doctrineConfig->dbal();
25+
$dbalConfig
26+
->connection('default')
27+
->url(env('DATABASE_URL')->resolve())
28+
->profilingCollectBacktrace(param('kernel.debug'))
29+
->useSavepoints(true);
30+
31+
$ormConfig = $doctrineConfig->orm();
32+
$ormConfig
33+
->autoGenerateProxyClasses(true)
34+
->enableLazyGhostObjects(true);
35+
36+
$entityManager = $ormConfig->entityManager('default');
37+
$entityManager
38+
->reportFieldsWhereDeclared(true)
39+
->validateXmlMapping(true)
40+
->namingStrategy('doctrine.orm.naming_strategy.underscore_number_aware')
41+
->autoMapping(true)
42+
->mapping('App', [
43+
'type' => 'attribute',
44+
'is_bundle' => false,
45+
'dir' => '%kernel.project_dir%/src/Entity',
46+
'prefix' => 'App\Entity',
47+
'alias' => 'App',
48+
]);
49+
50+
$ormConfig
51+
->controllerResolver()
52+
->autoMapping(true);
53+
54+
$entityManager->dql()
55+
->datetimeFunction('date', SimpleFunction::class)
56+
->datetimeFunction('time', SimpleFunction::class)
57+
->datetimeFunction('timestamp', SimpleFunction::class)
58+
->datetimeFunction('convert_tz', ConvertTz::class)
59+
->numericFunction('timestampdiff', TimestampDiff::class)
60+
->numericFunction('dayofyear', SimpleFunction::class)
61+
->numericFunction('dayofmonth', SimpleFunction::class)
62+
->numericFunction('dayofweek', SimpleFunction::class)
63+
->numericFunction('week', SimpleFunction::class)
64+
->numericFunction('day', SimpleFunction::class)
65+
->numericFunction('hour', SimpleFunction::class)
66+
->numericFunction('minute', SimpleFunction::class)
67+
->numericFunction('month', SimpleFunction::class)
68+
->numericFunction('quarter', SimpleFunction::class)
69+
->numericFunction('second', SimpleFunction::class)
70+
->numericFunction('year', SimpleFunction::class)
71+
->numericFunction('sign', Sign::class)
72+
->numericFunction('pow', Pow::class)
73+
->numericFunction('round', Round::class)
74+
->numericFunction('ceil', SimpleFunction::class)
75+
->stringFunction('md5', SimpleFunction::class)
76+
->stringFunction('group_concat', GroupConcat::class)
77+
->stringFunction('concat_ws', ConcatWs::class)
78+
->stringFunction('cast', Cast::class)
79+
->stringFunction('replace', Replace::class)
80+
->stringFunction('date_format', DateFormat::class);
81+
82+
if ('test' === $containerConfigurator->env()) {
83+
$dbalConfig
84+
->connection('default')
85+
->dbnameSuffix('_test.%env(default::TEST_TOKEN)%');
86+
}
87+
88+
if ('prod' === $containerConfigurator->env()) {
89+
$systemCachePool = 'doctrine.system_cache_pool';
90+
$resultCachePool = 'doctrine.result_cache_pool';
91+
92+
$ormConfig
93+
->autoGenerateProxyClasses(false)
94+
->proxyDir('%kernel.build_dir%/doctrine/orm/Proxies');
95+
96+
$entityManager
97+
->queryCacheDriver([
98+
'type' => 'pool',
99+
'pool' => $systemCachePool,
100+
]);
101+
102+
$entityManager
103+
->resultCacheDriver([
104+
'type' => 'pool',
105+
'pool' => $resultCachePool,
106+
]);
107+
108+
$cache = $frameworkConfig->cache();
109+
$cache->pool($systemCachePool, [
110+
'adapter' => 'cache.system',
111+
]);
112+
$cache->pool($resultCachePool, [
113+
'adapter' => 'cache.app',
114+
]);
115+
}
116+
};

config/packages/doctrine.yaml

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)