Skip to content

Commit 4d3c1df

Browse files
authored
Merge pull request #1990 from greg0ire/orm-34
Require ORM 3.4
2 parents b83ce1e + 1579ef3 commit 4d3c1df

27 files changed

+35
-398
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"require-dev": {
4646
"doctrine/coding-standard": "^13",
4747
"doctrine/deprecations": "^1.0",
48-
"doctrine/orm": "^3.1",
48+
"doctrine/orm": "^3.4.4",
4949
"friendsofphp/proxy-manager-lts": "^1.0",
5050
"phpstan/phpstan": "2.1.1",
5151
"phpstan/phpstan-phpunit": "2.0.3",

config/orm.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
use Doctrine\Persistence\Mapping\Driver\PHPDriver;
4343
use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver;
4444
use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver;
45-
use Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer;
4645
use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser;
4746
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
4847
use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaListener;
@@ -70,9 +69,6 @@
7069
->set('doctrine.orm.metadata.staticphp.class', StaticPHPDriver::class)
7170
->set('doctrine.orm.metadata.attribute.class', AttributeDriver::class)
7271

73-
// cache warmer
74-
->set('doctrine.orm.proxy_cache_warmer.class', ProxyCacheWarmer::class)
75-
7672
// form field factory guesser
7773
->set('form.type_guesser.doctrine.class', DoctrineOrmTypeGuesser::class)
7874

@@ -114,12 +110,6 @@
114110

115111
->alias(EntityManagerInterface::class, 'doctrine.orm.entity_manager')
116112

117-
->set('doctrine.orm.proxy_cache_warmer', param('doctrine.orm.proxy_cache_warmer.class'))
118-
->tag('kernel.cache_warmer')
119-
->args([
120-
service('doctrine'),
121-
])
122-
123113
->set('form.type_guesser.doctrine', param('form.type_guesser.doctrine.class'))
124114
->tag('form.type_guesser')
125115
->args([

config/schema/doctrine-1.0.xsd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@
146146
</xsd:choice>
147147

148148
<xsd:attribute name="default-entity-manager" type="xsd:string" />
149-
<xsd:attribute name="proxy-dir" type="xsd:string" />
150-
<xsd:attribute name="proxy-namespace" type="xsd:string" />
151-
<xsd:attribute name="auto-generate-proxy-classes" type="xsd:string" default="false" />
152149
<xsd:attribute name="enable-native-lazy-objects" type="xsd:boolean" />
153150
<xsd:attributeGroup ref="entity-manager-config" />
154151
</xsd:complexType>

docs/en/configuration.rst

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,9 @@ Configuration Reference
213213
orm:
214214
default_entity_manager: ~ # The first defined is used if not set
215215
216-
# Auto generate mode possible values are: "NEVER", "ALWAYS", "FILE_NOT_EXISTS", "EVAL", "FILE_NOT_EXISTS_OR_CHANGED"
217-
auto_generate_proxy_classes: false
218-
proxy_dir: "%kernel.cache_dir%/doctrine/orm/Proxies"
219-
proxy_namespace: Proxies
220-
# Enables the new native implementation of PHP lazy objects instead of generated proxies
221-
enable_native_lazy_objects: false
216+
# No-op, will be deprecated and removed in the future
217+
enable_native_lazy_objects: true
218+
222219
identity_generation_preferences:
223220
Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity
224221
@@ -494,13 +491,7 @@ Configuration Reference
494491
495492
</doctrine:dbal>
496493
497-
<!-- auto-generate-proxy-classes: Auto generate mode possible values are: "NEVER", "ALWAYS", "FILE_NOT_EXISTS", "EVAL, "FILE_NOT_EXISTS_OR_CHANGED" -->
498-
<doctrine:orm
499-
default-entity-manager="default"
500-
auto-generate-proxy-classes="false"
501-
proxy-dir="%kernel.cache_dir%/doctrine/orm/Proxies"
502-
proxy-namespace="Proxies"
503-
>
494+
<doctrine:orm default-entity-manager="default">
504495
505496
<!-- example -->
506497
<doctrine:entity-manager
@@ -659,9 +650,6 @@ the ORM resolves to:
659650
orm:
660651
auto_mapping: true
661652
# the standard distribution overrides this to be true in debug, false otherwise
662-
auto_generate_proxy_classes: false
663-
proxy_namespace: Proxies
664-
proxy_dir: "%kernel.cache_dir%/doctrine/orm/Proxies"
665653
default_entity_manager: default
666654
metadata_cache_driver: ~
667655
query_cache_driver: ~

phpunit.xml.dist

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
</testsuite>
1111
</testsuites>
1212

13-
<php>
14-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=./tests/baseline-ignore"/>
15-
</php>
16-
1713
<coverage>
1814
<include>
1915
<directory>src</directory>

src/CacheWarmer/DoctrineMetadataCacheWarmer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ public function __construct(
1919
parent::__construct($phpArrayFile);
2020
}
2121

22-
/**
23-
* It must not be optional because it should be called before ProxyCacheWarmer which is not optional.
24-
*/
2522
public function isOptional(): bool
2623
{
27-
return false;
24+
return true;
2825
}
2926

3027
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter, string|null $buildDir = null): bool

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
use Doctrine\ORM\EntityRepository;
77
use Doctrine\ORM\Mapping\ClassMetadata;
88
use Doctrine\ORM\Mapping\ClassMetadataFactory;
9-
use Doctrine\ORM\Proxy\ProxyFactory;
109
use InvalidArgumentException;
11-
use ReflectionClass;
1210
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1311
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
1412
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -27,16 +25,11 @@
2725
use function implode;
2826
use function in_array;
2927
use function is_array;
30-
use function is_bool;
31-
use function is_int;
3228
use function is_string;
3329
use function key;
3430
use function reset;
3531
use function sprintf;
36-
use function strlen;
37-
use function strpos;
3832
use function strtoupper;
39-
use function substr;
4033
use function trigger_deprecation;
4134

4235
/**
@@ -417,10 +410,7 @@ private function addOrmSection(ArrayNodeDefinition $node): void
417410
// Key that should not be rewritten to the entity-manager config
418411
$excludedKeys = [
419412
'default_entity_manager' => true,
420-
'auto_generate_proxy_classes' => true,
421413
'enable_native_lazy_objects' => true,
422-
'proxy_dir' => true,
423-
'proxy_namespace' => true,
424414
'resolve_target_entities' => true,
425415
'resolve_target_entity' => true,
426416
'controller_resolver' => true,
@@ -464,46 +454,9 @@ private function addOrmSection(ArrayNodeDefinition $node): void
464454
->end()
465455
->children()
466456
->scalarNode('default_entity_manager')->end()
467-
->scalarNode('auto_generate_proxy_classes')->defaultValue(false)
468-
->info('Auto generate mode possible values are: "NEVER", "ALWAYS", "FILE_NOT_EXISTS", "EVAL", "FILE_NOT_EXISTS_OR_CHANGED", this option is ignored when the "enable_native_lazy_objects" option is true')
469-
->validate()
470-
->ifTrue(function ($v) {
471-
$generationModes = $this->getAutoGenerateModes();
472-
473-
if (is_int($v) && in_array($v, $generationModes['values']/*array(0, 1, 2, 3)*/)) {
474-
return false;
475-
}
476-
477-
if (is_bool($v)) {
478-
return false;
479-
}
480-
481-
if (is_string($v)) {
482-
if (in_array(strtoupper($v), $generationModes['names']/*array('NEVER', 'ALWAYS', 'FILE_NOT_EXISTS', 'EVAL', 'FILE_NOT_EXISTS_OR_CHANGED')*/)) {
483-
return false;
484-
}
485-
}
486-
487-
return true;
488-
})
489-
->thenInvalid('Invalid auto generate mode value %s')
490-
->end()
491-
->validate()
492-
->ifString()
493-
->then(static fn (string $v) => constant('Doctrine\ORM\Proxy\ProxyFactory::AUTOGENERATE_' . strtoupper($v)))
494-
->end()
495-
->end()
496457
->booleanNode('enable_native_lazy_objects')
497-
->defaultFalse()
498-
->info('Enables the new native implementation of PHP lazy objects instead of generated proxies')
499-
->end()
500-
->scalarNode('proxy_dir')
501-
->defaultValue('%kernel.build_dir%/doctrine/orm/Proxies')
502-
->info('Configures the path where generated proxy classes are saved when using non-native lazy objects, this option is ignored when the "enable_native_lazy_objects" option is true')
503-
->end()
504-
->scalarNode('proxy_namespace')
505-
->defaultValue('Proxies')
506-
->info('Defines the root namespace for generated proxy classes when using non-native lazy objects, this option is ignored when the "enable_native_lazy_objects" option is true')
458+
->defaultTrue()
459+
->info('no-op, will be deprecated and removed in the future')
507460
->end()
508461
->arrayNode('controller_resolver')
509462
->canBeDisabled()
@@ -833,33 +786,4 @@ private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition
833786

834787
return $node;
835788
}
836-
837-
/**
838-
* Find proxy auto generate modes for their names and int values
839-
*
840-
* @return array{names: list<string>, values: list<int>}
841-
*/
842-
private function getAutoGenerateModes(): array
843-
{
844-
$constPrefix = 'AUTOGENERATE_';
845-
$prefixLen = strlen($constPrefix);
846-
$refClass = new ReflectionClass(ProxyFactory::class);
847-
$constsArray = $refClass->getConstants();
848-
$namesArray = [];
849-
$valuesArray = [];
850-
851-
foreach ($constsArray as $key => $value) {
852-
if (strpos($key, $constPrefix) !== 0) {
853-
continue;
854-
}
855-
856-
$namesArray[] = substr($key, $prefixLen);
857-
$valuesArray[] = (int) $value;
858-
}
859-
860-
return [
861-
'names' => $namesArray,
862-
'values' => $valuesArray,
863-
];
864-
}
865789
}

src/DependencyInjection/DoctrineExtension.php

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Doctrine\DBAL\Connection;
1717
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
1818
use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface;
19-
use Doctrine\ORM\Configuration as ORMConfiguration;
2019
use Doctrine\ORM\EntityManagerInterface;
2120
use Doctrine\ORM\Events;
2221
use Doctrine\ORM\Id\AbstractIdGenerator;
@@ -26,9 +25,7 @@
2625
use Doctrine\ORM\Mapping\Driver\StaticPHPDriver as LegacyStaticPHPDriver;
2726
use Doctrine\ORM\Mapping\Embeddable;
2827
use Doctrine\ORM\Mapping\Entity;
29-
use Doctrine\ORM\Mapping\LegacyReflectionFields;
3028
use Doctrine\ORM\Mapping\MappedSuperclass;
31-
use Doctrine\ORM\ORMSetup;
3229
use Doctrine\ORM\Proxy\Autoloader;
3330
use Doctrine\ORM\UnitOfWork;
3431
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
@@ -59,21 +56,16 @@
5956
use Symfony\Component\Messenger\MessageBusInterface;
6057
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
6158
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
62-
use Symfony\Component\VarExporter\ProxyHelper;
6359

6460
use function array_intersect_key;
6561
use function array_keys;
6662
use function array_merge;
67-
use function assert;
6863
use function class_exists;
6964
use function interface_exists;
70-
use function is_bool;
7165
use function is_dir;
72-
use function method_exists;
7366
use function reset;
7467
use function sprintf;
7568
use function str_replace;
76-
use function trigger_deprecation;
7769

7870
/**
7971
* DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
@@ -514,32 +506,6 @@ protected function ormLoad(array $config, ContainerBuilder $container): void
514506

515507
$container->setParameter('doctrine.default_entity_manager', $config['default_entity_manager']);
516508

517-
if (! class_exists(ProxyHelper::class)) {
518-
throw new LogicException(
519-
'Lazy ghost objects cannot be enabled because the "symfony/var-exporter" library'
520-
. ' is not installed. Please run "composer require symfony/var-exporter".',
521-
);
522-
}
523-
524-
if ($config['enable_native_lazy_objects'] ?? false) {
525-
/** @phpstan-ignore function.alreadyNarrowedType */
526-
if (! method_exists(ORMConfiguration::class, 'enableNativeLazyObjects')) {
527-
throw new LogicException(
528-
'Native lazy objects are not supported with your installed version of the ORM. Please upgrade to "doctrine/orm >= 3.4".',
529-
);
530-
}
531-
532-
$container->removeDefinition('doctrine.orm.proxy_cache_warmer');
533-
} else {
534-
// Only emit the deprecation notice for ORM 3 users
535-
trigger_deprecation('doctrine/doctrine-bundle', '2.16', 'Not setting "doctrine.orm.enable_native_lazy_objects" to true is deprecated.');
536-
}
537-
538-
$options = ['auto_generate_proxy_classes', 'enable_native_lazy_objects', 'proxy_dir', 'proxy_namespace'];
539-
foreach ($options as $key) {
540-
$container->setParameter('doctrine.orm.' . $key, $config[$key]);
541-
}
542-
543509
$container->setAlias('doctrine.orm.entity_manager', $defaultEntityManagerDefinitionId = sprintf('doctrine.orm.%s_entity_manager', $config['default_entity_manager']));
544510
$container->getAlias('doctrine.orm.entity_manager')->setPublic(true);
545511

@@ -642,13 +608,11 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
642608
}
643609

644610
$methods = [
611+
'enableNativeLazyObjects' => true,
645612
'setMetadataCache' => new Reference(sprintf('doctrine.orm.%s_metadata_cache', $entityManager['name'])),
646613
'setQueryCache' => new Reference(sprintf('doctrine.orm.%s_query_cache', $entityManager['name'])),
647614
'setResultCache' => new Reference(sprintf('doctrine.orm.%s_result_cache', $entityManager['name'])),
648615
'setMetadataDriverImpl' => new Reference('doctrine.orm.' . $entityManager['name'] . '_metadata_driver'),
649-
'setProxyDir' => '%doctrine.orm.proxy_dir%',
650-
'setProxyNamespace' => '%doctrine.orm.proxy_namespace%',
651-
'setAutoGenerateProxyClasses' => '%doctrine.orm.auto_generate_proxy_classes%',
652616
'setSchemaIgnoreClasses' => $entityManager['schema_ignore_classes'],
653617
'setClassMetadataFactoryName' => $entityManager['class_metadata_factory_name'],
654618
'setDefaultRepositoryClassName' => $entityManager['default_repository_class'],
@@ -659,24 +623,6 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
659623
'setIdentityGenerationPreferences' => $entityManager['identity_generation_preferences'],
660624
];
661625

662-
if (class_exists(LegacyReflectionFields::class)) {
663-
$enableNativeLazyObjects = $container->getParameter('doctrine.orm.enable_native_lazy_objects');
664-
665-
assert(is_bool($enableNativeLazyObjects));
666-
667-
$methods['enableNativeLazyObjects'] = $enableNativeLazyObjects;
668-
669-
// Do not set deprecated proxy configurations when native lazy objects are enabled with `doctrine/orm:^3.5`
670-
/** @phpstan-ignore function.alreadyNarrowedType */
671-
if ($enableNativeLazyObjects && method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) {
672-
unset(
673-
$methods['setProxyDir'],
674-
$methods['setProxyNamespace'],
675-
$methods['setAutoGenerateProxyClasses'],
676-
);
677-
}
678-
}
679-
680626
if (isset($entityManager['fetch_mode_subselect_batch_size'])) {
681627
$methods['setEagerFetchBatchSize'] = $entityManager['fetch_mode_subselect_batch_size'];
682628
}
@@ -1058,7 +1004,7 @@ private function createMetadataCache(string $objectManagerName, ContainerBuilder
10581004

10591005
$container->register($cacheWarmerServiceId, DoctrineMetadataCacheWarmer::class)
10601006
->setArguments([new Reference(sprintf('doctrine.orm.%s_entity_manager', $objectManagerName)), $phpArrayFile])
1061-
->addTag('kernel.cache_warmer', ['priority' => 1000]); // priority should be higher than ProxyCacheWarmer
1007+
->addTag('kernel.cache_warmer', ['priority' => 1000]);
10621008

10631009
$cache = new Definition(PhpArrayAdapter::class, [$phpArrayFile, $cache]);
10641010
}

0 commit comments

Comments
 (0)