Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection] Add test for issue #49591 #51123

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

Open
wants to merge 1 commit into
base: 6.3
Choose a base branch
Loading
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

/**
* @internal This class has been auto-generated by the Symfony Dependency Injection Component.
*/
class Symfony_DI_PhpDumper_Issues49591 extends Container
{
protected $parameters = [];
protected \Closure $getService;

public function __construct()
{
$this->services = $this->privates = [];
$this->methodMap = [
'connection' => 'getConnectionService',
'session' => 'getSessionService',
'subscriber' => 'getSubscriberService',
];

$this->aliases = [];
}

public function compile(): void
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
}

public function isCompiled(): bool
{
return true;
}

public function getRemovedIds(): array
{
return [
'.service_locator.SoPO3vR' => true,
'repository' => true,
];
}

/**
* Gets the public 'connection' shared service.
*
* @return \Symfony\Component\DependencyInjection\Tests\Connection
*/
protected static function getConnectionService($container)
{
return $container->services['connection'] = new \Symfony\Component\DependencyInjection\Tests\Connection(new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($container->getService ??= $container->getService(...), [
'subscriber' => ['services', 'subscriber', 'getSubscriberService', false],
], [
'subscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Subscriber',
]));
}

/**
* Gets the public 'session' shared service.
*
* @return \Symfony\Component\DependencyInjection\Tests\Session
*/
protected static function getSessionService($container)
{
$a = ($container->services['connection'] ?? self::getConnectionService($container));

if (isset($container->services['session'])) {
return $container->services['session'];
}

return $container->services['session'] = (new \Symfony\Component\DependencyInjection\Tests\Repository())->login($a);
}

/**
* Gets the public 'subscriber' shared service.
*
* @return \Symfony\Component\DependencyInjection\Tests\Subscriber
*/
protected static function getSubscriberService($container)
{
$a = ($container->services['session'] ?? self::getSessionService($container));

if (isset($container->services['subscriber'])) {
return $container->services['subscriber'];
}

return $container->services['subscriber'] = new \Symfony\Component\DependencyInjection\Tests\Subscriber($a);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?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\Component\DependencyInjection\Tests;

use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Reference;

class Issues49591Test extends TestCase
{
public function testServices()
{
$containerBuilder = new ContainerBuilder();

$containerBuilder->register('connection', Connection::class)
->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('subscriber', needsIndexes: true)))
->setPublic(true);

$containerBuilder->register('repository', Repository::class);

$containerBuilder->register('session', Session::class)
->setFactory([new Reference('repository'), 'login'])
->addArgument(new Reference('connection'))
->setPublic(true);

$containerBuilder->register('subscriber', Subscriber::class)
->addArgument(new Reference('session'))
->addTag('subscriber')
->setPublic(true);

$containerBuilder->compile();

$dumper = new PhpDumper($containerBuilder);
$dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Issues49591']);

eval('?>'.$dump);

$container = new \Symfony_DI_PhpDumper_Issues49591();

self::assertSame($container->get('session'), $container->get('subscriber')->session);
}
}

class Connection
{
public bool $connection = false;

public function __construct(public ContainerInterface $container)
{
}

public function connect()
{
if (!$this->connection) {
$this->connection = true;
$this->container->get('subscriber');
}
}
}

class Subscriber
{
public function __construct(public Session $session)
{
}
}

class Repository
{
public function login(Connection $connection)
{
$connection->connect();

return new Session();
}
}

class Session
{
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.