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
13 changes: 13 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ You can enable them through configuration:
$config->enableNativeLazyObjects(true);
```

As a consequence, methods, parameters and commands related to userland lazy
objects have been deprecated on PHP 8.4+:

- `Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand`
- `Doctrine\ORM\Configuration::getAutoGenerateProxyClasses()`
- `Doctrine\ORM\Configuration::getProxyDir()`
- `Doctrine\ORM\Configuration::getProxyNamespace()`
- `Doctrine\ORM\Configuration::setAutoGenerateProxyClasses()`
- `Doctrine\ORM\Configuration::setProxyDir()`
- `Doctrine\ORM\Configuration::setProxyNamespace()`
- Passing anything but `null` as $proxyDir argument to `Doctrine\ORM\ORMSetup` methods
- Passing more than one Argument to `Doctrine\ORM\Proxy\ProxyFactory::__construct()`

## Deprecate methods for configuring no longer configurable features

Since 3.0, lazy ghosts are enabled unconditionally, and so is rejecting ID
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The following Commands are currently available:
- ``orm:clear-cache:result`` Clear result cache of the various
cache drivers.
- ``orm:generate-proxies`` Generates proxy classes for entity
classes.
classes. Deprecated in favor of using native lazy objects.
- ``orm:run-dql`` Executes arbitrary DQL directly from the command
line.
- ``orm:schema-tool:create`` Processes the schema and either
Expand Down
54 changes: 54 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ public function getIdentityGenerationPreferences(): array
*/
public function setProxyDir(string $dir): void
{
if (PHP_VERSION_ID >= 80400) {
Deprecation::triggerIfCalledFromOutside(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
__METHOD__,
);
}

$this->attributes['proxyDir'] = $dir;
}

Expand All @@ -72,6 +81,15 @@ public function setProxyDir(string $dir): void
*/
public function getProxyDir(): string|null
{
if (PHP_VERSION_ID >= 80400) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
__METHOD__,
);
}

return $this->attributes['proxyDir'] ?? null;
}

Expand All @@ -82,6 +100,15 @@ public function getProxyDir(): string|null
*/
public function getAutoGenerateProxyClasses(): int
{
if (PHP_VERSION_ID >= 80400) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
__METHOD__,
);
}

return $this->attributes['autoGenerateProxyClasses'] ?? ProxyFactory::AUTOGENERATE_ALWAYS;
}

Expand All @@ -92,6 +119,15 @@ public function getAutoGenerateProxyClasses(): int
*/
public function setAutoGenerateProxyClasses(bool|int $autoGenerate): void
{
if (PHP_VERSION_ID >= 80400) {
Deprecation::triggerIfCalledFromOutside(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
__METHOD__,
);
}

$this->attributes['autoGenerateProxyClasses'] = (int) $autoGenerate;
}

Expand All @@ -100,6 +136,15 @@ public function setAutoGenerateProxyClasses(bool|int $autoGenerate): void
*/
public function getProxyNamespace(): string|null
{
if (PHP_VERSION_ID >= 80400) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
__METHOD__,
);
}

return $this->attributes['proxyNamespace'] ?? null;
}

Expand All @@ -108,6 +153,15 @@ public function getProxyNamespace(): string|null
*/
public function setProxyNamespace(string $ns): void
{
if (PHP_VERSION_ID >= 80400) {
Deprecation::triggerIfCalledFromOutside(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Calling %s is deprecated and will not be possible in Doctrine ORM 4.0.',
__METHOD__,
);
}

$this->attributes['proxyNamespace'] = $ns;
}

Expand Down
16 changes: 10 additions & 6 deletions src/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,16 @@ public function __construct(

$this->repositoryFactory = $config->getRepositoryFactory();
$this->unitOfWork = new UnitOfWork($this);
$this->proxyFactory = new ProxyFactory(
$this,
$config->getProxyDir(),
$config->getProxyNamespace(),
$config->getAutoGenerateProxyClasses(),
);
if ($config->isNativeLazyObjectsEnabled()) {
$this->proxyFactory = new ProxyFactory($this);
} else {
$this->proxyFactory = new ProxyFactory(
$this,
$config->getProxyDir(),
$config->getProxyNamespace(),
$config->getAutoGenerateProxyClasses(),
);
}

if ($config->isSecondLevelCacheEnabled()) {
$cacheConfig = $config->getSecondLevelCacheConfiguration();
Expand Down
30 changes: 30 additions & 0 deletions src/ORMSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ORM;

use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Psr\Cache\CacheItemPoolInterface;
Expand All @@ -20,6 +21,8 @@
use function md5;
use function sys_get_temp_dir;

use const PHP_VERSION_ID;

final class ORMSetup
{
/**
Expand All @@ -33,6 +36,15 @@
string|null $proxyDir = null,
CacheItemPoolInterface|null $cache = null,
): Configuration {
if (PHP_VERSION_ID >= 80400 && $proxyDir !== null) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Passing anything but null as $proxyDir to %s is deprecated and will not be possible in Doctrine ORM 3.0.',
__METHOD__,
);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derrabus @SenseException one way to be forward-compatible with the desired signature (one that omits $proxyDir while still specifying a cache is to use named arguments, but I haven't find a way to enforce that, so right now, I'm just deprecating passing null.

Do you know of a way to detect if $proxyDir was used (even with null)?
If not, then maybe I should create new methods like createAttributeMetadataConfig that do not have that argument and deprecate the Configuration-suffixed methods in favor of the Config-suffixed ones?

I have also considered doing some kind of CacheItemPoolInterface|string|null $proxyDirOrCache - based horror, but with named, arguments, that's a breaking change.

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create a dedicated PR shortly with the "new methods" solution. In the meantime, let's merge this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #12022


$config = self::createConfiguration($isDevMode, $proxyDir, $cache);
$config->setMetadataDriverImpl(new AttributeDriver($paths));

Expand All @@ -51,6 +63,15 @@
CacheItemPoolInterface|null $cache = null,
bool $isXsdValidationEnabled = true,
): Configuration {
if (PHP_VERSION_ID >= 80400 && $proxyDir !== null) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Passing anything but null as $proxyDir to %s is deprecated and will not be possible in Doctrine ORM 3.0.',
__METHOD__,
);

Check warning on line 72 in src/ORMSetup.php

View check run for this annotation

Codecov / codecov/patch

src/ORMSetup.php#L67-L72

Added lines #L67 - L72 were not covered by tests
}

$config = self::createConfiguration($isDevMode, $proxyDir, $cache);
$config->setMetadataDriverImpl(new XmlDriver($paths, XmlDriver::DEFAULT_FILE_EXTENSION, $isXsdValidationEnabled));

Expand All @@ -65,6 +86,15 @@
string|null $proxyDir = null,
CacheItemPoolInterface|null $cache = null,
): Configuration {
if (PHP_VERSION_ID >= 80400 && $proxyDir !== null) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Passing anything but null as $proxyDir to %s is deprecated and will not be possible in Doctrine ORM 3.0.',
__METHOD__,
);
}

$proxyDir = $proxyDir ?: sys_get_temp_dir();

$cache = self::createCacheInstance($isDevMode, $proxyDir, $cache);
Expand Down
11 changes: 11 additions & 0 deletions src/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ORM\Proxy;

use Closure;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityNotFoundException;
use Doctrine\ORM\ORMInvalidArgumentException;
Expand All @@ -30,6 +31,7 @@
use function file_exists;
use function file_put_contents;
use function filemtime;
use function func_num_args;
use function is_bool;
use function is_dir;
use function is_int;
Expand Down Expand Up @@ -150,6 +152,15 @@ public function __construct(
string|null $proxyNs = null,
bool|int $autoGenerate = self::AUTOGENERATE_NEVER,
) {
if (PHP_VERSION_ID >= 80400 && func_num_args() > 1) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Passing more than just the EntityManager to the %s is deprecated and will not be possible in Doctrine ORM 4.0.',
__METHOD__,
);
}

if (! $proxyDir && ! $em->getConfiguration()->isNativeLazyObjectsEnabled()) {
throw ORMInvalidArgumentException::proxyDirectoryRequired();
}
Expand Down
11 changes: 11 additions & 0 deletions src/Tools/Console/Command/GenerateProxiesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ORM\Tools\Console\Command;

use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Tools\Console\MetadataFilter;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -19,6 +20,8 @@
use function realpath;
use function sprintf;

use const PHP_VERSION_ID;

/**
* Command to (re)generate the proxy classes used by doctrine.
*
Expand All @@ -39,6 +42,14 @@

protected function execute(InputInterface $input, OutputInterface $output): int
{
if (PHP_VERSION_ID >= 80400) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/12005',
'Generating proxies is deprecated and will be impossible in Doctrine ORM 4.0.',
);

Check warning on line 50 in src/Tools/Console/Command/GenerateProxiesCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Tools/Console/Command/GenerateProxiesCommand.php#L45-L50

Added lines #L45 - L50 were not covered by tests
}

$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$em = $this->getEntityManager($input);
Expand Down
3 changes: 3 additions & 0 deletions tests/Tests/ORM/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected function setUp(): void
$this->configuration = new Configuration();
}

#[WithoutErrorHandler]
public function testSetGetProxyDir(): void
{
self::assertNull($this->configuration->getProxyDir()); // defaults
Expand All @@ -47,6 +48,7 @@ public function testSetGetProxyDir(): void
self::assertSame(__DIR__, $this->configuration->getProxyDir());
}

#[WithoutErrorHandler]
public function testSetGetAutoGenerateProxyClasses(): void
{
self::assertSame(ProxyFactory::AUTOGENERATE_ALWAYS, $this->configuration->getAutoGenerateProxyClasses()); // defaults
Expand All @@ -61,6 +63,7 @@ public function testSetGetAutoGenerateProxyClasses(): void
self::assertSame(ProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS, $this->configuration->getAutoGenerateProxyClasses());
}

#[WithoutErrorHandler]
public function testSetGetProxyNamespace(): void
{
self::assertNull($this->configuration->getProxyNamespace()); // defaults
Expand Down
6 changes: 3 additions & 3 deletions tests/Tests/TestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ public static function configureProxies(Configuration $configuration): void
$enableNativeLazyObjects = true;
}

$configuration->setProxyDir(__DIR__ . '/Proxies');
$configuration->setProxyNamespace('Doctrine\Tests\Proxies');

if (PHP_VERSION_ID >= 80400 && $enableNativeLazyObjects) {
$configuration->enableNativeLazyObjects(true);

return;
}

$configuration->setProxyDir(__DIR__ . '/Proxies');
$configuration->setProxyNamespace('Doctrine\Tests\Proxies');
}

private static function initializeDatabase(): void
Expand Down