8000 [ProxyManagerBridge] Deprecate the package by nicolas-grekas · Pull Request #48484 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[ProxyManagerBridge] Deprecate the package #48484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2022
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
136 changes: 136 additions & 0 deletions src/Symfony/Bridge/Doctrine/Tests/LegacyManagerRegistryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests;

use PHPUnit\Framework\TestCase;
use ProxyManager\Proxy\LazyLoadingInterface;
use ProxyManager\Proxy\ValueHolderInterface;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper\PhpDumperTest;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\Filesystem\Filesystem;

/**
* @group legacy
*/
class LegacyManagerRegistryTest extends TestCase
{
public static function setUpBeforeClass(): void
{
$test = new PhpDumperTest();
$test->testDumpContainerWithProxyServiceWillShareProxies();
}

public function testResetService()
{
$container = new \LazyServiceProjectServiceContainer();

$registry = new TestManagerRegistry('name', [], ['defaultManager' => 'foo'], 'defaultConnection', 'defaultManager', 'proxyInterfaceName');
$registry->setTestContainer($container);

$foo = $container->get('foo');
$foo->bar = 123;
$this->assertTrue(isset($foo->bar));

$registry->resetManager();

$this->assertSame($foo, $container->get('foo'));
$this->assertObjectNotHasAttribute('bar', $foo);
}

/**
* When performing an entity manager lazy service reset, the reset operations may re-use the container
* to create a "fresh" service: when doing so, it can happen that the "fresh" service is itself a proxy.
*
* Because of that, the proxy will be populated with a wrapped value that is itself a proxy: repeating
* the reset operation keeps increasing this nesting until the application eventually runs into stack
* overflow or memory overflow operations, which can happen for long-running processes that rely on
* services that are reset very often.
*/
public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther()
{
// This test scenario only applies to containers composed as a set of generated sources
$this->dumpLazyServiceProjectAsFilesServiceContainer();

/** @var ContainerInterface $container */
$container = new \LazyServiceProjectAsFilesServiceContainer();

$registry = new TestManagerRegistry(
'irrelevant',
[],
['defaultManager' => 'foo'],
'irrelevant',
'defaultManager',
'irrelevant'
);
$registry->setTestContainer($container);

$service = $container->get('foo');

self::assertInstanceOf(\stdClass::class, $service);
self::assertInstanceOf(LazyLoadingInterface::class, $service);
self::assertInstanceOf(ValueHolderInterface::class, $service);
self::assertFalse($service->isProxyInitialized());

$service->initializeProxy();

self::assertTrue($container->initialized('foo'));
self::assertTrue($service->isProxyInitialized());

$registry->resetManager();
$service->initializeProxy();

$wrappedValue = $service->getWrappedValueHolderValue();
self::assertInstanceOf(\stdClass::class, $wrappedValue);
self::assertNotInstanceOf(LazyLoadingInterface::class, $wrappedValue);
self::assertNotInstanceOf(ValueHolderInterface::class, $wrappedValue);
}

private function dumpLazyServiceProjectAsFilesServiceContainer()
{
if (class_exists(\LazyServiceProjectAsFilesServiceContainer::class, false)) {
return;
}

$container = new ContainerBuilder();

$container->register('foo', \stdClass::class)
->setPublic(true)
->setLazy(true);
$container->compile();

$fileSystem = new Filesystem();

$temporaryPath = $fileSystem->tempnam(sys_get_temp_dir(), 'symfonyManagerRegistryTest');
$fileSystem->remove($temporaryPath);
$fileSystem->mkdir($temporaryPath);

$dumper = new PhpDumper($container);

$dumper->setProxyDumper(new ProxyDumper());
$containerFiles = $dumper->dump([
'class' => 'LazyServiceProjectAsFilesServiceContainer',
'as_files' => true,
]);

array_walk(
$containerFiles,
static function (string $containerSources, string $fileName) use ($temporaryPath): void {
(new Filesystem())->dumpFile($temporaryPath.'/'.$fileName, $containerSources);
}
);

require $temporaryPath.'/LazyServiceProjectAsFilesServiceContainer.php';
}
}
63 changes: 25 additions & 38 deletions src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,29 @@
namespace Symfony\Bridge\Doctrine\Tests;

use PHPUnit\Framework\TestCase;
use ProxyManager\Proxy\LazyLoadingInterface;
use ProxyManager\Proxy\ValueHolderInterface;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper\PhpDumperTest;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\VarExporter\LazyObjectInterface;

class ManagerRegistryTest extends TestCase
{
public static function setUpBeforeClass(): void
{
$test = new PhpDumperTest();
$test->testDumpContainerWithProxyServiceWillShareProxies();
$container = new ContainerBuilder();

$container->register('foo', \stdClass::class)->setPublic(true);
$container->getDefinition('foo')->setLazy(true)->addTag('proxy', ['interface' => \stdClass::class]);
$container->compile();

$dumper = new PhpDumper($container);
eval('?>'.$dumper->dump(['class' => 'LazyServiceDoctrineBridgeContainer']));
}

public function testResetService()
{
$container = new \LazyServiceProjectServiceContainer();
$container = new \LazyServiceDoctrineBridgeContainer();

$registry = new TestManagerRegistry('name', [], ['defaultManager' => 'foo'], 'defaultConnection', 'defaultManager', 'proxyInterfaceName');
$registry->setTestContainer($container);
Expand All @@ -59,10 +61,10 @@ public function testResetService()
public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther()
{
// This test scenario only applies to containers composed as a set of generated sources
$this->dumpLazyServiceProjectAsFilesServiceContainer();
$this->dumpLazyServiceDoctrineBridgeContainerAsFiles();

/** @var ContainerInterface $container */
$container = new \LazyServiceProjectAsFilesServiceContainer();
$container = new \LazyServiceDoctrineBridgeContainerAsFiles();

$registry = new TestManagerRegistry(
'irrelevant',
Expand All @@ -77,35 +79,34 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther()
$service = $container->get('foo');

self::assertInstanceOf(\stdClass::class, $service);
self::assertInstanceOf(LazyLoadingInterface::class, $service);
self::assertInstanceOf(ValueHolderInterface::class, $service);
self::assertFalse($service->isProxyInitialized());
self::assertInstanceOf(LazyObjectInterface::class, $service);
self::assertFalse($service->isLazyObjectInitialized());

$service->initializeProxy();
$service->initializeLazyObject();

self::assertTrue($container->initialized('foo'));
self::assertTrue($service->isProxyInitialized());
self::assertTrue($service->isLazyObjectInitialized());

$registry->resetManager();
$service->initializeProxy();
$service->initializeLazyObject();

$wrappedValue = $service->getWrappedValueHolderValue();
$wrappedValue = $service->initializeLazyObject();
self::assertInstanceOf(\stdClass::class, $wrappedValue);
self::assertNotInstanceOf(LazyLoadingInterface::class, $wrappedValue);
self::assertNotInstanceOf(ValueHolderInterface::class, $wrappedValue);
self::assertNotInstanceOf(LazyObjectInterface::class, $wrappedValue);
}

private function dumpLazyServiceProjectAsFilesServiceContainer()
private function dumpLazyServiceDoctrineBridgeContainerAsFiles()
{
if (class_exists(\LazyServiceProjectAsFilesServiceContainer::class, false)) {
if (class_exists(\LazyServiceDoctrineBridgeContainerAsFiles::class, false)) {
return;
}

$container = new ContainerBuilder();

$container->register('foo', \stdClass::class)
->setPublic(true)
->setLazy(true);
->setLazy(true)
->addTag('proxy', ['interface' => \stdClass::class]);
$container->compile();

$fileSystem = new Filesystem();
Expand All @@ -116,9 +117,8 @@ private function dumpLazyServiceProjectAsFilesServiceContainer()

$dumper = new PhpDumper($container);

$dumper->setProxyDumper(new ProxyDumper());
$containerFiles = $dumper->dump([
'class' => 'LazyServiceProjectAsFilesServiceContainer',
'class' => 'LazyServiceDoctrineBridgeContainerAsFiles',
'as_files' => true,
]);

Expand All @@ -129,19 +129,6 @@ static function (string $containerSources, string $fileName) use ($temporaryPath
}
);

require $temporaryPath.'/LazyServiceProjectAsFilesServiceContainer.php';
}
}

class TestManagerRegistry extends ManagerRegistry
{
public function setTestContainer($container)
{
$this->container = $container;
}

public function getAliasNamespace($alias): string
{
return 'Foo';
require $temporaryPath.'/LazyServiceDoctrineBridgeContainerAsFiles.php';
}
}
27 changes: 27 additions & 0 deletions src/Symfony/Bridge/Doctrine/Tests/TestManagerRegistry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests;

use Symfony\Bridge\Doctrine\ManagerRegistry;

class TestManagerRegistry extends ManagerRegistry
{
public function setTestContainer($container)
{
$this->container = $container;
}

public function getAliasNamespace($alias): string
{
return 'Foo';
}
}
5 changes: 2 additions & 3 deletions src/Symfony/Bridge/Doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
"symfony/stopwatch": "^5.4|^6.0",
"symfony/cache": "^5.4|^6.0",
"symfony/config": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/dependency-injection": "^6.2",
"symfony/form": "^5.4.9|^6.0.9",
"symfony/http-kernel": "^6.2",
"symfony/messenger": "^5.4|^6.0",
"symfony/doctrine-messenger": "^5.4|^6.0",
"symfony/property-access": "^5.4|^6.0",
"symfony/property-info": "^5.4|^6.0",
"symfony/proxy-manager-bridge": "^5.4|^6.0",
"symfony/security-core": "^6.0",
"symfony/expression-language": "^5.4|^6.0",
"symfony/uid": "^5.4|^6.0",
Expand All @@ -55,7 +54,7 @@
"doctrine/orm": "<2.7.4",
"phpunit/phpunit": "<5.4.3",
"symfony/cache": "<5.4",
"symfony/dependency-injection": "<5.4",
"symfony/dependency-injection": "<6.2",
"symfony/form": "<5.4",
"symfony/http-kernel": "<6.2",
"symfony/messenger": "<5.4",
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Bridge/ProxyManager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.3
---

* Deprecate the bridge

4.2.0
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface;

trigger_deprecation('symfony/proxy-manager-bridge', '6.3', 'The "symfony/proxy-manager-bridge" package is deprecated and can be removed from your dependencies.');

/**
* Runtime lazy loading proxy generator.
*
* @author Marco Pivetta <ocramius@gmail.com>
*
* @deprecated since Symfony 6.3
*/
class RuntimeInstantiator implements InstantiatorInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;

trigger_deprecation('symfony/proxy-manager-bridge', '6.3', 'The "symfony/proxy-manager-bridge" package is deprecated and can be removed from your dependencies.');

/**
* Generates dumped PHP code of proxies via reflection.
*
* @author Marco Pivetta <ocramius@gmail.com>
*
* @deprecated since Symfony 6.3
*
* @final
*/
class ProxyDumper implements DumperInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* with the ProxyManager bridge.
*
* @author Marco Pivetta <ocramius@gmail.com>
*
* @group legacy
*/
class ContainerBuilderTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* with the ProxyManager bridge.
*
* @author Marco Pivetta <ocramius@gmail.com>
*
* @group legacy
*/
class PhpDumperTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* Tests for {@see \Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator}.
*
* @author Marco Pivetta <ocramius@gmail.com>
*
* @group legacy
*/
class RuntimeInstantiatorTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Tests for {@see \Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper}.
*
* @author Marco Pivetta <ocramius@gmail.com>
*
* @group legacy
*/
class ProxyDumperTest extends TestCase
{
Expand Down
Loading
0