Skip to content

Commit eae6341

Browse files
committed
[DependencyInjection] Add test for issue #49591
1 parent 8613ff6 commit eae6341

File tree

2 files changed

+191
-0
lines changed

2 files changed

+191
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
4+
use Symfony\Component\DependencyInjection\ContainerInterface;
5+
use Symfony\Component\DependencyInjection\Container;
6+
use Symfony\Component\DependencyInjection\Exception\LogicException;
7+
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
8+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
11+
12+
/**
13+
* @internal This class has been auto-generated by the Symfony Dependency Injection Component.
14+
*/
15+
class Symfony_DI_PhpDumper_Issues49591 extends Container
16+
{
17+
protected $parameters = [];
18+
protected \Closure $getService;
19+
20+
public function __construct()
21+
{
22+
$this->getService = $this->getService(...);
23+
$this->services = $this->privates = [];
24+
$this->methodMap = [
25+
'connection' => 'getConnectionService',
26+
'session' => 'getSessionService',
27+
'subscriber' => 'getSubscriberService',
28+
];
29+
30+
$this->aliases = [];
31+
}
32+
33+
public function compile(): void
34+
{
35+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
36+
}
37+
38+
public function isCompiled(): bool
39+
{
40+
return true;
41+
}
42+
43+
public function getRemovedIds(): array
44+
{
45+
return [
46+
'.service_locator.SoPO3vR' => true,
47+
'repository' => true,
48+
];
49+
}
50+
51+
/**
52+
* Gets the public 'connection' shared service.
53+
*
54+
* @return \Symfony\Component\DependencyInjection\Tests\Connection
55+
*/
56+
protected function getConnectionService()
57+
{
58+
return $this->services['connection'] = new \Symfony\Component\DependencyInjection\Tests\Connection(new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($this->getService, [
59+
'subscriber' => ['services', 'subscriber', 'getSubscriberService', false],
60+
], [
61+
'subscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Subscriber',
62+
]));
63+
}
64+
65+
/**
66+
* Gets the public 'session' shared service.
67+
*
68+
* @return \Symfony\Component\DependencyInjection\Tests\Session
69+
*/
70+
protected function getSessionService()
71+
{
72+
$a = ($this->services['connection'] ?? $this->getConnectionService());
73+
74+
if (isset($this->services['session'])) {
75+
return $this->services['session'];
76+
}
77+
78+
return $this->services['session'] = (new \Symfony\Component\DependencyInjection\Tests\Repository())->login($a);
79+
}
80+
81+
/**
82+
* Gets the public 'subscriber' shared service.
83+
*
84+
* @return \Symfony\Component\DependencyInjection\Tests\Subscriber
85+
*/
86+
protected function getSubscriberService()
87+
{
88+
$a = ($this->services['session'] ?? $this->getSessionService());
89+
90+
if (isset($this->services['subscriber'])) {
91+
return $this->services['subscriber'];
92+
}
93+
94+
return $this->services['subscriber'] = new \Symfony\Component\DependencyInjection\Tests\Subscriber($a);
95+
}
96+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Psr\Container\ContainerInterface;
16+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
17+
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
20+
use Symfony\Component\DependencyInjection\Reference;
21+
22+
class Issues49591Test extends TestCase
23+
{
24+
public function testServices()
25+
{
26+
$containerBuilder = new ContainerBuilder();
27+
28+
$containerBuilder->register('connection', Connection::class)
29+
->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('subscriber', needsIndexes: true)))
30+
->setPublic(true);
31+
32+
$containerBuilder->register('repository', Repository::class);
33+
34+
$containerBuilder->register('session', Session::class)
35+
->setFactory([new Reference('repository'), 'login'])
36+
->addArgument(new Reference('connection'))
37+
->setPublic(true);
38+
39+
$containerBuilder->register('subscriber', Subscriber::class)
40+
->addArgument(new Reference('session'))
41+
->addTag('subscriber')
42+
->setPublic(true);
43+
44+
$containerBuilder->compile();
45+
46+
$dumper = new PhpDumper($containerBuilder);
47+
$dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Issues49591']);
48+
49+
self::assertStringEqualsFile(__DIR__.'/Fixtures/php/services_issues49591.php', $dump);
50+
51+
eval('?>'.$dump);
52+
53+
$container = new \Symfony_DI_PhpDumper_Issues49591();
54+
55+
self::assertSame($container->get('session'), $container->get('subscriber')->session);
56+
}
57+
}
58+
59+
class Connection
60+
{
61+
public bool $connection = false;
62+
63+
public function __construct(public ContainerInterface $container)
64+
{
65+
}
66+
67+
public function connect()
68+
{
69+
if (!$this->connection) {
70+
$this->connection = true;
71+
$this->container->get('subscriber');
72+
}
73+
}
74+
}
75+
76+
class Subscriber
77+
{
78+
public function __construct(public Session $session)
79+
{
80+
}
81+
}
82+
83+
class Repository
84+
{
85+
public function login(Connection $connection)
86+
{
87+
$connection->connect();
88+
89+
return new Session();
90+
}
91+
}
92+
93+
class Session
94+
{
95+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy