Skip to content

Commit

Permalink
Use lazy ghosts unconditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Oct 7, 2023
1 parent 46ef989 commit e0b53bf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 80 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ jobs:
- "default"
extension:
- "pdo_sqlite"
proxy:
- "common"
include:
- php-version: "8.2"
dbal-version: "3@dev"
Expand All @@ -51,10 +49,6 @@ jobs:
- php-version: "8.2"
dbal-version: "default"
extension: "sqlite3"
- php-version: "8.1"
dbal-version: "default"
proxy: "lazy-ghost"
extension: "pdo_sqlite"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -83,13 +77,11 @@ jobs:
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage-no-cache.xml"
env:
ENABLE_SECOND_LEVEL_CACHE: 0
ORM_PROXY_IMPLEMENTATION: "${{ matrix.proxy }}"

- name: "Run PHPUnit with Second Level Cache"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-cache.xml"
env:
ENABLE_SECOND_LEVEL_CACHE: 1
ORM_PROXY_IMPLEMENTATION: "${{ matrix.proxy }}"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v3"
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Upgrade to 3.0

## BC BREAK: lazy ghosts are enabled unconditionally

`Doctrine\ORM\Configuration::setLazyGhostObjectEnabled()` and
`Doctrine\ORM\Configuration::isLazyGhostObjectEnabled()` are now no-ops and
will be deprecated in 3.1.0

## BC BREAK: Lifecycle callback mapping on embedded classes is now explicitly forbidden

Lifecycle callback mapping on embedded classes produced no effect, and is now
Expand Down
27 changes: 7 additions & 20 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@
use Doctrine\ORM\Repository\DefaultRepositoryFactory;
use Doctrine\ORM\Repository\RepositoryFactory;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use LogicException;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\VarExporter\LazyGhostTrait;

use function class_exists;
use function is_a;
use function strtolower;
use function trait_exists;

/**
* Configuration container for all configuration options of Doctrine.
Expand Down Expand Up @@ -581,28 +577,19 @@ public function setSchemaIgnoreClasses(array $schemaIgnoreClasses): void
$this->attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses;
}

/**
* To be deprecated in 3.1.0
*
* @return true
*/
public function isLazyGhostObjectEnabled(): bool
{
return $this->attributes['isLazyGhostObjectEnabled'] ?? false;
return true;
}

/** To be deprecated in 3.1.0 */
public function setLazyGhostObjectEnabled(bool $flag): void
{
if ($flag && ! trait_exists(LazyGhostTrait::class)) {
throw new LogicException(
'Lazy ghost objects cannot be enabled because the "symfony/var-exporter" library'
. ' version 6.2 or higher is not installed. Please run "composer require symfony/var-exporter:^6.2".',
);
}

if ($flag && ! class_exists(RuntimeReflectionProperty::class)) {
throw new LogicException(
'Lazy ghost objects cannot be enabled because the "doctrine/persistence" library'
. ' version 3.1 or higher is not installed. Please run "composer update doctrine/persistence".',
);
}

$this->attributes['isLazyGhostObjectEnabled'] = $flag;
}

public function setRejectIdCollisionInIdentityMap(bool $flag): void
Expand Down
31 changes: 0 additions & 31 deletions lib/Doctrine/ORM/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Doctrine\Common\Proxy\AbstractProxyFactory;
use Doctrine\Common\Proxy\Proxy as CommonProxy;
use Doctrine\Common\Proxy\ProxyDefinition;
use Doctrine\Common\Proxy\ProxyGenerator;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityNotFoundException;
use Doctrine\ORM\ORMInvalidArgumentException;
Expand Down Expand Up @@ -51,7 +49,6 @@
use function ucfirst;

use const DIRECTORY_SEPARATOR;
use const PHP_VERSION_ID;

/**
* This factory is used to create proxy objects for entities at runtime.
Expand Down Expand Up @@ -137,9 +134,6 @@ public function __serialize(): array
/** @var array<class-string, Closure> */
private $proxyFactories = [];

/** @var bool */
private $isLazyGhostObjectEnabled = true;

/**
* Initializes a new instance of the <tt>ProxyFactory</tt> class that is
* connected to the given <tt>EntityManager</tt>.
Expand All @@ -155,23 +149,6 @@ public function __construct(
private readonly string $proxyNs,
bool|int $autoGenerate = self::AUTOGENERATE_NEVER,
) {
if (! $em->getConfiguration()->isLazyGhostObjectEnabled()) {
if (PHP_VERSION_ID >= 80100) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/10837/',
'Not enabling lazy ghost objects is deprecated and will not be supported in Doctrine ORM 3.0. Ensure Doctrine\ORM\Configuration::setLazyGhostObjectEnabled(true) is called to enable them.',
);
}

$this->isLazyGhostObjectEnabled = false;

$proxyGenerator = new ProxyGenerator($proxyDir, $proxyNs);
$proxyGenerator->setPlaceholder('baseProxyInterface', CommonProxy::class . ', \\' . InternalProxy::class);

parent::__construct($proxyGenerator, $em->getMetadataFactory(), $autoGenerate);
}

if (! $proxyDir) {
throw ORMInvalidArgumentException::proxyDirectoryRequired();
}
Expand All @@ -195,10 +172,6 @@ public function __construct(
*/
public function getProxy($className, array $identifier)
{
if (! $this->isLazyGhostObjectEnabled) {
return parent::getProxy($className, $identifier);
}

$proxyFactory = $this->proxyFactories[$className] ?? $this->getProxyFactory($className);

return $proxyFactory($identifier);
Expand All @@ -216,10 +189,6 @@ public function getProxy($className, array $identifier)
*/
public function generateProxyClasses(array $classes, $proxyDir = null)
{
if (! $this->isLazyGhostObjectEnabled) {
return parent::generateProxyClasses($classes, $proxyDir);
}

$generated = 0;

foreach ($classes as $class) {
Expand Down
21 changes: 0 additions & 21 deletions tests/Doctrine/Tests/TestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,18 @@
use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\ORM\Configuration;
use LogicException;
use Symfony\Component\VarExporter\LazyGhostTrait;
use UnexpectedValueException;

use function assert;
use function class_exists;
use function explode;
use function fwrite;
use function get_debug_type;
use function getenv;
use function in_array;
use function sprintf;
use function str_starts_with;
use function strlen;
use function substr;
use function trait_exists;

use const STDERR;

Expand Down Expand Up @@ -95,23 +91,6 @@ public static function configureProxies(Configuration $configuration): void
{
$configuration->setProxyDir(__DIR__ . '/Proxies');
$configuration->setProxyNamespace('Doctrine\Tests\Proxies');

$proxyImplementation = getenv('ORM_PROXY_IMPLEMENTATION')
?: (trait_exists(LazyGhostTrait::class) ? 'lazy-ghost' : 'common');

switch ($proxyImplementation) {
case 'lazy-ghost':
$configuration->setLazyGhostObjectEnabled(true);

return;

case 'common':
$configuration->setLazyGhostObjectEnabled(false);

return;
}

throw new LogicException(sprintf('Unknown proxy implementation: %s.', $proxyImplementation));
}

private static function initializeDatabase(): void
Expand Down

0 comments on commit e0b53bf

Please sign in to comment.