Skip to content

Commit eb2e7d9

Browse files
authored
Merge pull request #12020 from greg0ire/depr-legacy-proxy
Deprecate more proxies-related methods or calls
2 parents a4b2035 + 2550b2d commit eb2e7d9

File tree

9 files changed

+136
-10
lines changed

9 files changed

+136
-10
lines changed

UPGRADE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ You can enable them through configuration:
1111
$config->enableNativeLazyObjects(true);
1212
```
1313

14+
As a consequence, methods, parameters and commands related to userland lazy
15+
objects have been deprecated on PHP 8.4+:
16+
17+
- `Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand`
18+
- `Doctrine\ORM\Configuration::getAutoGenerateProxyClasses()`
19+
- `Doctrine\ORM\Configuration::getProxyDir()`
20+
- `Doctrine\ORM\Configuration::getProxyNamespace()`
21+
- `Doctrine\ORM\Configuration::setAutoGenerateProxyClasses()`
22+
- `Doctrine\ORM\Configuration::setProxyDir()`
23+
- `Doctrine\ORM\Configuration::setProxyNamespace()`
24+
- Passing anything but `null` as $proxyDir argument to `Doctrine\ORM\ORMSetup` methods
25+
- Passing more than one Argument to `Doctrine\ORM\Proxy\ProxyFactory::__construct()`
26+
1427
## Deprecate methods for configuring no longer configurable features
1528

1629
Since 3.0, lazy ghosts are enabled unconditionally, and so is rejecting ID

docs/en/reference/tools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The following Commands are currently available:
8484
- ``orm:clear-cache:result`` Clear result cache of the various
8585
cache drivers.
8686
- ``orm:generate-proxies`` Generates proxy classes for entity
87-
classes.
87+
classes. Deprecated in favor of using native lazy objects.
8888
- ``orm:run-dql`` Executes arbitrary DQL directly from the command
8989
line.
9090
- ``orm:schema-tool:create`` Processes the schema and either

src/Configuration.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ public function getIdentityGenerationPreferences(): array
6464
*/
6565
public function setProxyDir(string $dir): void
6666
{
67+
if (PHP_VERSION_ID >= 80400) {
68+
Deprecation::triggerIfCalledFromOutside(
69+
'doctrine/orm',
70+
'https://github.com/doctrine/orm/pull/12005',
71+
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
72+
__METHOD__,
73+
);
74+
}
75+
6776
$this->attributes['proxyDir'] = $dir;
6877
}
6978

@@ -72,6 +81,15 @@ public function setProxyDir(string $dir): void
7281
*/
7382
public function getProxyDir(): string|null
7483
{
84+
if (PHP_VERSION_ID >= 80400) {
85+
Deprecation::trigger(
86+
'doctrine/orm',
87+
'https://github.com/doctrine/orm/pull/12005',
88+
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
89+
__METHOD__,
90+
);
91+
}
92+
7593
return $this->attributes['proxyDir'] ?? null;
7694
}
7795

@@ -82,6 +100,15 @@ public function getProxyDir(): string|null
82100
*/
83101
public function getAutoGenerateProxyClasses(): int
84102
{
103+
if (PHP_VERSION_ID >= 80400) {
104+
Deprecation::trigger(
105+
'doctrine/orm',
106+
'https://github.com/doctrine/orm/pull/12005',
107+
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
108+
__METHOD__,
109+
);
110+
}
111+
85112
return $this->attributes['autoGenerateProxyClasses'] ?? ProxyFactory::AUTOGENERATE_ALWAYS;
86113
}
87114

@@ -92,6 +119,15 @@ public function getAutoGenerateProxyClasses(): int
92119
*/
93120
public function setAutoGenerateProxyClasses(bool|int $autoGenerate): void
94121
{
122+
if (PHP_VERSION_ID >= 80400) {
123+
Deprecation::triggerIfCalledFromOutside(
124+
'doctrine/orm',
125+
'https://github.com/doctrine/orm/pull/12005',
126+
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
127+
__METHOD__,
128+
);
129+
}
130+
95131
$this->attributes['autoGenerateProxyClasses'] = (int) $autoGenerate;
96132
}
97133

@@ -100,6 +136,15 @@ public function setAutoGenerateProxyClasses(bool|int $autoGenerate): void
100136
*/
101137
public function getProxyNamespace(): string|null
102138
{
139+
if (PHP_VERSION_ID >= 80400) {
140+
Deprecation::trigger(
141+
'doctrine/orm',
142+
'https://github.com/doctrine/orm/pull/12005',
143+
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
144+
__METHOD__,
145+
);
146+
}
147+
103148
return $this->attributes['proxyNamespace'] ?? null;
104149
}
105150

@@ -108,6 +153,15 @@ public function getProxyNamespace(): string|null
108153
*/
109154
public function setProxyNamespace(string $ns): void
110155
{
156+
if (PHP_VERSION_ID >= 80400) {
157+
Deprecation::triggerIfCalledFromOutside(
158+
'doctrine/orm',
159+
'https://github.com/doctrine/orm/pull/12005',
160+
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
161+
__METHOD__,
162+
);
163+
}
164+
111165
$this->attributes['proxyNamespace'] = $ns;
112166
}
113167

src/EntityManager.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,16 @@ public function __construct(
134134

135135
$this->repositoryFactory = $config->getRepositoryFactory();
136136
$this->unitOfWork = new UnitOfWork($this);
137-
$this->proxyFactory = new ProxyFactory(
138-
$this,
139-
$config->getProxyDir(),
140-
$config->getProxyNamespace(),
141-
$config->getAutoGenerateProxyClasses(),
142-
);
137+
if ($config->isNativeLazyObjectsEnabled()) {
138+
$this->proxyFactory = new ProxyFactory($this);
139+
} else {
140+
$this->proxyFactory = new ProxyFactory(
141+
$this,
142+
$config->getProxyDir(),
143+
$config->getProxyNamespace(),
144+
$config->getAutoGenerateProxyClasses(),
145+
);
146+
}
143147

144148
if ($config->isSecondLevelCacheEnabled()) {
145149
$cacheConfig = $config->getSecondLevelCacheConfiguration();

src/ORMSetup.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\ORM;
66

7+
use Doctrine\Deprecations\Deprecation;
78
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
89
use Doctrine\ORM\Mapping\Driver\XmlDriver;
910
use Psr\Cache\CacheItemPoolInterface;
@@ -20,6 +21,8 @@
2021
use function md5;
2122
use function sys_get_temp_dir;
2223

24+
use const PHP_VERSION_ID;
25+
2326
final class ORMSetup
2427
{
2528
/**
@@ -33,6 +36,15 @@ public static function createAttributeMetadataConfiguration(
3336
string|null $proxyDir = null,
3437
CacheItemPoolInterface|null $cache = null,
3538
): Configuration {
39+
if (PHP_VERSION_ID >= 80400 && $proxyDir !== null) {
40+
Deprecation::trigger(
41+
'doctrine/orm',
42+
'https://github.com/doctrine/orm/pull/12005',
43+
'Passing anything but null as $proxyDir to %s is deprecated and will not be possible in Doctrine ORM 3.0.',
44+
__METHOD__,
45+
);
46+
}
47+
3648
$config = self::createConfiguration($isDevMode, $proxyDir, $cache);
3749
$config->setMetadataDriverImpl(new AttributeDriver($paths));
3850

@@ -51,6 +63,15 @@ public static function createXMLMetadataConfiguration(
5163
CacheItemPoolInterface|null $cache = null,
5264
bool $isXsdValidationEnabled = true,
5365
): Configuration {
66+
if (PHP_VERSION_ID >= 80400 && $proxyDir !== null) {
67+
Deprecation::trigger(
68+
'doctrine/orm',
69+
'https://github.com/doctrine/orm/pull/12005',
70+
'Passing anything but null as $proxyDir to %s is deprecated and will not be possible in Doctrine ORM 3.0.',
71+
__METHOD__,
72+
);
73+
}
74+
5475
$config = self::createConfiguration($isDevMode, $proxyDir, $cache);
5576
$config->setMetadataDriverImpl(new XmlDriver($paths, XmlDriver::DEFAULT_FILE_EXTENSION, $isXsdValidationEnabled));
5677

@@ -65,6 +86,15 @@ public static function createConfiguration(
6586
string|null $proxyDir = null,
6687
CacheItemPoolInterface|null $cache = null,
6788
): Configuration {
89+
if (PHP_VERSION_ID >= 80400 && $proxyDir !== null) {
90+
Deprecation::trigger(
91+
'doctrine/orm',
92+
'https://github.com/doctrine/orm/pull/12005',
93+
'Passing anything but null as $proxyDir to %s is deprecated and will not be possible in Doctrine ORM 3.0.',
94+
__METHOD__,
95+
);
96+
}
97+
6898
$proxyDir = $proxyDir ?: sys_get_temp_dir();
6999

70100
$cache = self::createCacheInstance($isDevMode, $proxyDir, $cache);

src/Proxy/ProxyFactory.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ORM\Proxy;
66

77
use Closure;
8+
use Doctrine\Deprecations\Deprecation;
89
use Doctrine\ORM\EntityManagerInterface;
910
use Doctrine\ORM\EntityNotFoundException;
1011
use Doctrine\ORM\ORMInvalidArgumentException;
@@ -30,6 +31,7 @@
3031
use function file_exists;
3132
use function file_put_contents;
3233
use function filemtime;
34+
use function func_num_args;
3335
use function is_bool;
3436
use function is_dir;
3537
use function is_int;
@@ -150,6 +152,15 @@ public function __construct(
150152
string|null $proxyNs = null,
151153
bool|int $autoGenerate = self::AUTOGENERATE_NEVER,
152154
) {
155+
if (PHP_VERSION_ID >= 80400 && func_num_args() > 1) {
156+
Deprecation::trigger(
157+
'doctrine/orm',
158+
'https://github.com/doctrine/orm/pull/12005',
159+
'Passing more than just the EntityManager to the %s is deprecated and will not be possible in Doctrine ORM 4.0.',
160+
__METHOD__,
161+
);
162+
}
163+
153164
if (! $proxyDir && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
154165
throw ORMInvalidArgumentException::proxyDirectoryRequired();
155166
}

src/Tools/Console/Command/GenerateProxiesCommand.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\ORM\Tools\Console\Command;
66

7+
use Doctrine\Deprecations\Deprecation;
78
use Doctrine\ORM\Tools\Console\MetadataFilter;
89
use InvalidArgumentException;
910
use Symfony\Component\Console\Input\InputArgument;
@@ -19,6 +20,8 @@
1920
use function realpath;
2021
use function sprintf;
2122

23+
use const PHP_VERSION_ID;
24+
2225
/**
2326
* Command to (re)generate the proxy classes used by doctrine.
2427
*
@@ -39,6 +42,14 @@ protected function configure(): void
3942

4043
protected function execute(InputInterface $input, OutputInterface $output): int
4144
{
45+
if (PHP_VERSION_ID >= 80400) {
46+
Deprecation::trigger(
47+
'doctrine/orm',
48+
'https://github.com/doctrine/orm/pull/12005',
49+
'Generating proxies is deprecated and will be impossible in Doctrine ORM 4.0.',
50+
);
51+
}
52+
4253
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
4354

4455
$em = $this->getEntityManager($input);

tests/Tests/ORM/ConfigurationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected function setUp(): void
3939
$this->configuration = new Configuration();
4040
}
4141

42+
#[WithoutErrorHandler]
4243
public function testSetGetProxyDir(): void
4344
{
4445
self::assertNull($this->configuration->getProxyDir()); // defaults
@@ -47,6 +48,7 @@ public function testSetGetProxyDir(): void
4748
self::assertSame(__DIR__, $this->configuration->getProxyDir());
4849
}
4950

51+
#[WithoutErrorHandler]
5052
public function testSetGetAutoGenerateProxyClasses(): void
5153
{
5254
self::assertSame(ProxyFactory::AUTOGENERATE_ALWAYS, $this->configuration->getAutoGenerateProxyClasses()); // defaults
@@ -61,6 +63,7 @@ public function testSetGetAutoGenerateProxyClasses(): void
6163
self::assertSame(ProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS, $this->configuration->getAutoGenerateProxyClasses());
6264
}
6365

66+
#[WithoutErrorHandler]
6467
public function testSetGetProxyNamespace(): void
6568
{
6669
self::assertNull($this->configuration->getProxyNamespace()); // defaults

tests/Tests/TestUtil.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ public static function configureProxies(Configuration $configuration): void
100100
$enableNativeLazyObjects = true;
101101
}
102102

103-
$configuration->setProxyDir(__DIR__ . '/Proxies');
104-
$configuration->setProxyNamespace('Doctrine\Tests\Proxies');
105-
106103
if (PHP_VERSION_ID >= 80400 && $enableNativeLazyObjects) {
107104
$configuration->enableNativeLazyObjects(true);
108105

109106
return;
110107
}
108+
109+
$configuration->setProxyDir(__DIR__ . '/Proxies');
110+
$configuration->setProxyNamespace('Doctrine\Tests\Proxies');
111111
}
112112

113113
private static function initializeDatabase(): void

0 commit comments

Comments
 (0)