Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"require-dev": {
"doctrine/coding-standard": "^13",
"doctrine/deprecations": "^1.0",
"doctrine/orm": "^3.1",
"doctrine/orm": "^3.4.4",
"friendsofphp/proxy-manager-lts": "^1.0",
"phpstan/phpstan": "2.1.1",
"phpstan/phpstan-phpunit": "2.0.3",
Expand Down
10 changes: 0 additions & 10 deletions config/orm.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
use Doctrine\Persistence\Mapping\Driver\PHPDriver;
use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver;
use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver;
use Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer;
use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaListener;
Expand Down Expand Up @@ -70,9 +69,6 @@
->set('doctrine.orm.metadata.staticphp.class', StaticPHPDriver::class)
->set('doctrine.orm.metadata.attribute.class', AttributeDriver::class)

// cache warmer
->set('doctrine.orm.proxy_cache_warmer.class', ProxyCacheWarmer::class)

// form field factory guesser
->set('form.type_guesser.doctrine.class', DoctrineOrmTypeGuesser::class)

Expand Down Expand Up @@ -114,12 +110,6 @@

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

->set('doctrine.orm.proxy_cache_warmer', param('doctrine.orm.proxy_cache_warmer.class'))
->tag('kernel.cache_warmer')
->args([
service('doctrine'),
])

->set('form.type_guesser.doctrine', param('form.type_guesser.doctrine.class'))
->tag('form.type_guesser')
->args([
Expand Down
3 changes: 0 additions & 3 deletions config/schema/doctrine-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@
</xsd:choice>

<xsd:attribute name="default-entity-manager" type="xsd:string" />
<xsd:attribute name="proxy-dir" type="xsd:string" />
<xsd:attribute name="proxy-namespace" type="xsd:string" />
<xsd:attribute name="auto-generate-proxy-classes" type="xsd:string" default="false" />
<xsd:attribute name="enable-native-lazy-objects" type="xsd:boolean" />
<xsd:attributeGroup ref="entity-manager-config" />
</xsd:complexType>
Expand Down
20 changes: 4 additions & 16 deletions docs/en/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,9 @@ Configuration Reference
orm:
default_entity_manager: ~ # The first defined is used if not set

# Auto generate mode possible values are: "NEVER", "ALWAYS", "FILE_NOT_EXISTS", "EVAL", "FILE_NOT_EXISTS_OR_CHANGED"
auto_generate_proxy_classes: false
proxy_dir: "%kernel.cache_dir%/doctrine/orm/Proxies"
proxy_namespace: Proxies
# Enables the new native implementation of PHP lazy objects instead of generated proxies
enable_native_lazy_objects: false
# No-op, will be deprecated and removed in the future
enable_native_lazy_objects: true

identity_generation_preferences:
Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity

Expand Down Expand Up @@ -494,13 +491,7 @@ Configuration Reference

</doctrine:dbal>

<!-- auto-generate-proxy-classes: Auto generate mode possible values are: "NEVER", "ALWAYS", "FILE_NOT_EXISTS", "EVAL, "FILE_NOT_EXISTS_OR_CHANGED" -->
<doctrine:orm
default-entity-manager="default"
auto-generate-proxy-classes="false"
proxy-dir="%kernel.cache_dir%/doctrine/orm/Proxies"
proxy-namespace="Proxies"
>
<doctrine:orm default-entity-manager="default">

<!-- example -->
<doctrine:entity-manager
Expand Down Expand Up @@ -659,9 +650,6 @@ the ORM resolves to:
orm:
auto_mapping: true
# the standard distribution overrides this to be true in debug, false otherwise
auto_generate_proxy_classes: false
proxy_namespace: Proxies
proxy_dir: "%kernel.cache_dir%/doctrine/orm/Proxies"
default_entity_manager: default
metadata_cache_driver: ~
query_cache_driver: ~
Expand Down
4 changes: 0 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
</testsuite>
</testsuites>

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=./tests/baseline-ignore"/>
</php>

<coverage>
<include>
<directory>src</directory>
Expand Down
5 changes: 1 addition & 4 deletions src/CacheWarmer/DoctrineMetadataCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ public function __construct(
parent::__construct($phpArrayFile);
}

/**
* It must not be optional because it should be called before ProxyCacheWarmer which is not optional.
*/
public function isOptional(): bool
{
return false;
return true;
}

protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter, string|null $buildDir = null): bool
Expand Down
80 changes: 2 additions & 78 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Proxy\ProxyFactory;
use InvalidArgumentException;
use ReflectionClass;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand All @@ -27,16 +25,11 @@
use function implode;
use function in_array;
use function is_array;
use function is_bool;
use function is_int;
use function is_string;
use function key;
use function reset;
use function sprintf;
use function strlen;
use function strpos;
use function strtoupper;
use function substr;
use function trigger_deprecation;

/**
Expand Down Expand Up @@ -417,10 +410,7 @@ private function addOrmSection(ArrayNodeDefinition $node): void
// Key that should not be rewritten to the entity-manager config
$excludedKeys = [
'default_entity_manager' => true,
'auto_generate_proxy_classes' => true,
'enable_native_lazy_objects' => true,
'proxy_dir' => true,
'proxy_namespace' => true,
'resolve_target_entities' => true,
'resolve_target_entity' => true,
'controller_resolver' => true,
Expand Down Expand Up @@ -464,46 +454,9 @@ private function addOrmSection(ArrayNodeDefinition $node): void
->end()
->children()
->scalarNode('default_entity_manager')->end()
->scalarNode('auto_generate_proxy_classes')->defaultValue(false)
->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')
->validate()
->ifTrue(function ($v) {
$generationModes = $this->getAutoGenerateModes();

if (is_int($v) && in_array($v, $generationModes['values']/*array(0, 1, 2, 3)*/)) {
return false;
}

if (is_bool($v)) {
return false;
}

if (is_string($v)) {
if (in_array(strtoupper($v), $generationModes['names']/*array('NEVER', 'ALWAYS', 'FILE_NOT_EXISTS', 'EVAL', 'FILE_NOT_EXISTS_OR_CHANGED')*/)) {
return false;
}
}

return true;
})
->thenInvalid('Invalid auto generate mode value %s')
->end()
->validate()
->ifString()
->then(static fn (string $v) => constant('Doctrine\ORM\Proxy\ProxyFactory::AUTOGENERATE_' . strtoupper($v)))
->end()
->end()
->booleanNode('enable_native_lazy_objects')
->defaultFalse()
->info('Enables the new native implementation of PHP lazy objects instead of generated proxies')
->end()
->scalarNode('proxy_dir')
->defaultValue('%kernel.build_dir%/doctrine/orm/Proxies')
->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')
->end()
->scalarNode('proxy_namespace')
->defaultValue('Proxies')
->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')
->defaultTrue()
->info('no-op, will be deprecated and removed in the future')
->end()
->arrayNode('controller_resolver')
->canBeDisabled()
Expand Down Expand Up @@ -833,33 +786,4 @@ private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition

return $node;
}

/**
* Find proxy auto generate modes for their names and int values
*
* @return array{names: list<string>, values: list<int>}
*/
private function getAutoGenerateModes(): array
{
$constPrefix = 'AUTOGENERATE_';
$prefixLen = strlen($constPrefix);
$refClass = new ReflectionClass(ProxyFactory::class);
$constsArray = $refClass->getConstants();
$namesArray = [];
$valuesArray = [];

foreach ($constsArray as $key => $value) {
if (strpos($key, $constPrefix) !== 0) {
continue;
}

$namesArray[] = substr($key, $prefixLen);
$valuesArray[] = (int) $value;
}

return [
'names' => $namesArray,
'values' => $valuesArray,
];
}
}
58 changes: 2 additions & 56 deletions src/DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface;
use Doctrine\ORM\Configuration as ORMConfiguration;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Events;
use Doctrine\ORM\Id\AbstractIdGenerator;
Expand All @@ -26,9 +25,7 @@
use Doctrine\ORM\Mapping\Driver\StaticPHPDriver as LegacyStaticPHPDriver;
use Doctrine\ORM\Mapping\Embeddable;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\LegacyReflectionFields;
use Doctrine\ORM\Mapping\MappedSuperclass;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Proxy\Autoloader;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
Expand Down Expand Up @@ -59,21 +56,16 @@
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
use Symfony\Component\VarExporter\ProxyHelper;

use function array_intersect_key;
use function array_keys;
use function array_merge;
use function assert;
use function class_exists;
use function interface_exists;
use function is_bool;
use function is_dir;
use function method_exists;
use function reset;
use function sprintf;
use function str_replace;
use function trigger_deprecation;

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

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

if (! class_exists(ProxyHelper::class)) {
throw new LogicException(
'Lazy ghost objects cannot be enabled because the "symfony/var-exporter" library'
. ' is not installed. Please run "composer require symfony/var-exporter".',
);
}

if ($config['enable_native_lazy_objects'] ?? false) {
/** @phpstan-ignore function.alreadyNarrowedType */
if (! method_exists(ORMConfiguration::class, 'enableNativeLazyObjects')) {
throw new LogicException(
'Native lazy objects are not supported with your installed version of the ORM. Please upgrade to "doctrine/orm >= 3.4".',
);
}

$container->removeDefinition('doctrine.orm.proxy_cache_warmer');
} else {
// Only emit the deprecation notice for ORM 3 users
trigger_deprecation('doctrine/doctrine-bundle', '2.16', 'Not setting "doctrine.orm.enable_native_lazy_objects" to true is deprecated.');
}

$options = ['auto_generate_proxy_classes', 'enable_native_lazy_objects', 'proxy_dir', 'proxy_namespace'];
foreach ($options as $key) {
$container->setParameter('doctrine.orm.' . $key, $config[$key]);
}

$container->setAlias('doctrine.orm.entity_manager', $defaultEntityManagerDefinitionId = sprintf('doctrine.orm.%s_entity_manager', $config['default_entity_manager']));
$container->getAlias('doctrine.orm.entity_manager')->setPublic(true);

Expand Down Expand Up @@ -642,13 +608,11 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
}

$methods = [
'enableNativeLazyObjects' => true,
'setMetadataCache' => new Reference(sprintf('doctrine.orm.%s_metadata_cache', $entityManager['name'])),
'setQueryCache' => new Reference(sprintf('doctrine.orm.%s_query_cache', $entityManager['name'])),
'setResultCache' => new Reference(sprintf('doctrine.orm.%s_result_cache', $entityManager['name'])),
'setMetadataDriverImpl' => new Reference('doctrine.orm.' . $entityManager['name'] . '_metadata_driver'),
'setProxyDir' => '%doctrine.orm.proxy_dir%',
'setProxyNamespace' => '%doctrine.orm.proxy_namespace%',
'setAutoGenerateProxyClasses' => '%doctrine.orm.auto_generate_proxy_classes%',
'setSchemaIgnoreClasses' => $entityManager['schema_ignore_classes'],
'setClassMetadataFactoryName' => $entityManager['class_metadata_factory_name'],
'setDefaultRepositoryClassName' => $entityManager['default_repository_class'],
Expand All @@ -659,24 +623,6 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
'setIdentityGenerationPreferences' => $entityManager['identity_generation_preferences'],
];

if (class_exists(LegacyReflectionFields::class)) {
$enableNativeLazyObjects = $container->getParameter('doctrine.orm.enable_native_lazy_objects');

assert(is_bool($enableNativeLazyObjects));

$methods['enableNativeLazyObjects'] = $enableNativeLazyObjects;

// Do not set deprecated proxy configurations when native lazy objects are enabled with `doctrine/orm:^3.5`
/** @phpstan-ignore function.alreadyNarrowedType */
if ($enableNativeLazyObjects && method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) {
unset(
$methods['setProxyDir'],
$methods['setProxyNamespace'],
$methods['setAutoGenerateProxyClasses'],
);
}
}

if (isset($entityManager['fetch_mode_subselect_batch_size'])) {
$methods['setEagerFetchBatchSize'] = $entityManager['fetch_mode_subselect_batch_size'];
}
Expand Down Expand Up @@ -1058,7 +1004,7 @@ private function createMetadataCache(string $objectManagerName, ContainerBuilder

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

$cache = new Definition(PhpArrayAdapter::class, [$phpArrayFile, $cache]);
}
Expand Down
Loading