resetManager example

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

        $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->assertInstanceOf(\stdClass::class$foo);
        $this->assertFalse(property_exists($foo, 'bar'));
    }

    /** * 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 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->assertInstanceOf(\stdClass::class$foo);
        $this->assertFalse(property_exists($foo, 'bar'));
    }

    /** * 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. */

        $connection = $entityManager->getConnection();

        try {
            $connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
        } catch (DBALException) {
            $connection->close();
            $connection->connect();
        }

        if (!$entityManager->isOpen()) {
            $this->managerRegistry->resetManager($this->entityManagerName);
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.