8000 [DependencyInjection] Wither private service fix by cs278 · Pull Request #48815 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Wither private service fix #48815

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

Closed
wants to merge 2 commits into from
Closed
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
Expand Up @@ -1073,7 +1073,7 @@ private function addInlineService(string $id, Definition $definition, Definition
}

$code .= $this->addServiceProperties($inlineDef, $name);
$code .= $this->addServiceMethodCalls($inlineDef, $name, !$this->getProxyDumper()->isProxyCandidate($inlineDef) && $inlineDef->isShared() && !isset($this->singleUsePrivateIds[$id]) ? $id : null);
$code .= $this->addServiceMethodCalls($inlineDef, $name, !$this->getProxyDumper()->isProxyCandidate($inlineDef) && $inlineDef->isPublic() && $inlineDef->isShared() && !isset($this->singleUsePrivateIds[$id]) ? $id : null);
$code .= $this->addServiceConfigurator($inlineDef, $name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\DependencyInjection\Tests\Compiler\Foo;
use Symfony\Component\DependencyInjection\Tests\Compiler\Wither;
use Symfony\Component\DependencyInjection\Tests\Compiler\WitherConsumer;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithEnumAttribute;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooUnitEnum;
Expand Down Expand Up @@ -1458,6 +1459,34 @@ public function testWither()
$this->assertInstanceOf(Foo::class, $wither->foo);
}

public function testWitherPrivate()
{
$container = new ContainerBuilder();
$container->register(Foo::class);

$container
->register('wither', Wither::class)
->setPublic(false)
->setAutowired(true)
;

$container
->register('wither_consumer', WitherConsumer::class)
->setPublic(true)
->addArgument(new Reference('wither'));

$container->compile();
$dumper = new PhpDumper($container);
$dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Service_WitherPrivate']);
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_wither_private.php', $dump);
eval('?>'.$dump);

$container = new \Symfony_DI_PhpDumper_Service_WitherPrivate();

$witherConsumer = $container->get('wither_consumer');
$this->assertInstanceOf(Foo::class, $witherConsumer->wither->foo);
}

/**
* @requires PHP 8
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ public function withFoo2(Foo $foo): self
}
}

final class WitherConsumer
{
public $wither;

public function __construct(Wither $wither)
{
$this->wither = $wither;
}
}

class SetterInjectionParent
{
/** @required*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
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_Service_WitherPrivate extends Container
{
protected $parameters = [];

public function __construct()
{
$this->services = $this->privates = [];
$this->methodMap = [
'wither_consumer' => 'getWitherConsumerService',
];

$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 [
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo' => true,
'wither' => true,
];
}

/**
* Gets the public 'wither_consumer' shared service.
*
* @return \Symfony\Component\DependencyInjection\Tests\Compiler\WitherConsumer
*/
protected function getWitherConsumerService()
{
$a = new \Symfony\Component\DependencyInjection\Tests\Compiler\Wither();

$b = new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo();

$a = $a->withFoo1($b);
$a = $a->withFoo2($b);
$a->setFoo($b);

return $this->services['wither_consumer'] = new \Symfony\Component\DependencyInjection\Tests\Compiler\WitherConsumer($a);
}
}
0