Skip to content

Commit 68f27ef

Browse files
Merge branch '6.3' into 6.4
* 6.3: [Runtime][ErrorHandler] Don't mess with ini_set('assert.warning') [DependencyInjection] Fix fetching lazy non-shared services multiple times [FrameworkBundle] Run the `ResolveFactoryClassPass` when `lint:container` builds the container from a dump
2 parents 80f1096 + 431d321 commit 68f27ef

File tree

8 files changed

+241
-4
lines changed

8 files changed

+241
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Console\Style\SymfonyStyle;
2222
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
2323
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
24+
use Symfony\Component\DependencyInjection\Compiler\ResolveFactoryClassPass;
2425
use Symfony\Component\DependencyInjection\Container;
2526
use Symfony\Component\DependencyInjection\ContainerBuilder;
2627
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@@ -99,7 +100,7 @@ private function getContainerBuilder(): ContainerBuilder
99100
$refl->setValue($parameterBag, true);
100101

101102
$container->getCompilerPassConfig()->setBeforeOptimizationPasses([]);
102-
$container->getCompilerPassConfig()->setOptimizationPasses([]);
103+
$container->getCompilerPassConfig()->setOptimizationPasses([new ResolveFactoryClassPass()]);
103104
$container->getCompilerPassConfig()->setBeforeRemovingPasses([]);
104105
}
105106

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,8 @@ protected static function {$methodName}(\$container$lazyInitialization)
930930

931931
if ($asFile) {
932932
$code .= "self::do(...);\n\n";
933+
} elseif ($definition->isPublic()) {
934+
$code .= sprintf("fn () => self::%s(\$container);\n\n", $methodName);
933935
} else {
934936
$code .= sprintf("self::%s(...);\n\n", $methodName);
935937
}

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,42 @@ public function testInlinedDefinitionReferencingServiceContainer()
767767
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services13.php', $dumper->dump(), '->dump() dumps inline definitions which reference service_container');
768768
}
769769

770+
public function testNonSharedLazy()
771+
{
772+
$container = new ContainerBuilder();
773+
774+
$container
775+
->register('foo', Foo::class)
776+
->setFile(realpath(self::$fixturesPath.'/includes/foo_lazy.php'))
777+
->setShared(false)
778+
->setLazy(true)
779+
->setPublic(true);
780+
781+
$container->compile();
782+
$dumper = new PhpDumper($container);
783+
$dump = $dumper->dump([
784+
'class' => 'Symfony_DI_PhpDumper_Service_Non_Shared_Lazy',
785+
'file' => __DIR__,
786+
'inline_factories' => false,
787+
'inline_class_loader' => false,
788+
]);
789+
$this->assertStringEqualsFile(
790+
self::$fixturesPath.'/php/services_non_shared_lazy_public.php',
791+
'\\' === \DIRECTORY_SEPARATOR ? str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump) : $dump
792+
);
793+
eval('?>'.$dump);
794+
795+
$container = new \Symfony_DI_PhpDumper_Service_Non_Shared_Lazy();
796+
797+
$foo1 = $container->get('foo');
798+
$this->assertTrue($foo1->resetLazyObject());
799+
800+
$foo2 = $container->get('foo');
801+
$this->assertTrue($foo2->resetLazyObject());
802+
803+
$this->assertNotSame($foo1, $foo2);
804+
}
805+
770806
/**
771807
* @testWith [false]
772808
* [true]
@@ -775,7 +811,7 @@ public function testNonSharedLazyDefinitionReferences(bool $asGhostObject)
775811
{
776812
$container = new ContainerBuilder();
777813
$container->register('foo', 'stdClass')->setShared(false)->setLazy(true);
778-
$container->register('bar', 'stdClass')->addArgument(new Reference('foo', ContainerBuilder::EXCEPTION_ON_INVALID_REFERENCE, false))->setPublic(true);
814+
$container->register('bar', 'stdClass')->addArgument(new Reference('foo', ContainerBuilder::EXCEPTION_ON_INVALID_REFERENCE))->setPublic(true);
779815
$container->compile();
780816

781817
$dumper = new PhpDumper($container);
@@ -1563,6 +1599,37 @@ public function testLazyWither()
15631599
$this->assertTrue($wither->resetLazyObject());
15641600
}
15651601

1602+
public function testLazyWitherNonShared()
1603+
{
1604+
$container = new ContainerBuilder();
1605+
$container->register(Foo::class);
1606+
1607+
$container
1608+
->register('wither', Wither::class)
1609+
->setShared(false)
1610+
->setLazy(true)
1611+
->setPublic(true)
1612+
->setAutowired(true);
1613+
1614+
$container->compile();
1615+
$dumper = new PhpDumper($container);
1616+
$dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Service_Wither_Lazy_Non_Shared']);
1617+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_wither_lazy_non_shared.php', $dump);
1618+
eval('?>'.$dump);
1619+
1620+
$container = new \Symfony_DI_PhpDumper_Service_Wither_Lazy_Non_Shared();
1621+
1622+
$wither1 = $container->get('wither');
1623+
$this->assertInstanceOf(Foo::class, $wither1->foo);
1624+
$this->assertTrue($wither1->resetLazyObject());
1625+
1626+
$wither2 = $container->get('wither');
1627+
$this->assertInstanceOf(Foo::class, $wither2->foo);
1628+
$this->assertTrue($wither2->resetLazyObject());
1629+
1630+
$this->assertNotSame($wither1, $wither2);
1631+
}
1632+
15661633
public function testWitherWithStaticReturnType()
15671634
{
15681635
$container = new ContainerBuilder();
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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_Service_Non_Shared_Lazy extends Container
16+
{
17+
protected $parameters = [];
18+
19+
public function __construct()
20+
{
21+
$this->services = $this->privates = [];
22+
$this->methodMap = [
23+
'foo' => 'getFooService',
24+
];
25+
26+
$this->aliases = [];
27+
}
28+
29+
public function compile(): void
30+
{
31+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
32+
}
33+
34+
public function isCompiled(): bool
35+
{
36+
return true;
37+
}
38+
39+
protected function createProxy($class, \Closure $factory)
40+
{
41+
return $factory();
42+
}
43+
44+
/**
45+
* Gets the public 'foo' service.
46+
*
47+
* @return \Symfony\Component\DependencyInjection\Tests\Compiler\Foo
48+
*/
49+
protected static function getFooService($container, $lazyLoad = true)
50+
{
51+
$container->factories['foo'] ??= fn () => self::getFooService($container);
52+
53+
if (true === $lazyLoad) {
54+
return $container->createProxy('FooGhost80f7cfc', static fn () => \FooGhost80f7cfc::createLazyGhost(static fn ($proxy) => self::getFooService($container, $proxy)));
55+
}
56+
57+
static $include = true;
58+
59+
if ($include) {
60+
include_once __DIR__.'/Fixtures/includes/foo_lazy.php';
61+
62+
$include = false;
63+
}
64+
65+
return $lazyLoad;
66+
}
67+
}
68+
69+
class FooGhost80f7cfc extends \Symfony\Component\DependencyInjection\Tests\Compiler\Foo implements \Symfony\Component\VarExporter\LazyObjectInterface
70+
{
71+
use \Symfony\Component\VarExporter\LazyGhostTrait;
72+
73+
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
74+
}
75+
76+
// Help opcache.preload discover always-needed symbols
77+
class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class);
78+
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class);
79+
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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_Service_Wither_Lazy_Non_Shared extends Container
16+
{
17+
protected $parameters = [];
18+
19+
public function __construct()
20+
{
21+
$this->services = $this->privates = [];
22+
$this->methodMap = [
23+
'wither' => 'getWitherService',
24+
];
25+
26+
$this->aliases = [];
27+
}
28+
29+
public function compile(): void
30+
{
31+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
32+
}
33+
34+
public function isCompiled(): bool
35+
{
36+
return true;
37+
}
38+
39+
public function getRemovedIds(): array
40+
{
41+
return [
42+
'Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo' => true,
43+
];
44+
}
45+
46+
protected function createProxy($class, \Closure $factory)
47+
{
48+
return $factory();
49+
}
50+
51+
/**
52+
* Gets the public 'wither' autowired service.
53+
*
54+
* @return \Symfony\Component\DependencyInjection\Tests\Compiler\Wither
55+
*/
56+
protected static function getWitherService($container, $lazyLoad = true)
57+
{
58+
$container->factories['wither'] ??= fn () => self::getWitherService($container);
59+
60+
if (true === $lazyLoad) {
61+
return $container->createProxy('WitherProxyDd381be', static fn () => \WitherProxyDd381be::createLazyProxy(static fn () => self::getWitherService($container, false)));
62+
}
63+
64+
$instance = new \Symfony\Component\DependencyInjection\Tests\Compiler\Wither();
65+
66+
$a = ($container->privates['Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] ??= new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo());
67+
68+
$instance = $instance->withFoo1($a);
69+
$instance = $instance->withFoo2($a);
70+
$instance->setFoo($a);
71+
72+
return $instance;
73+
}
74+
}
75+
76+
class WitherProxyDd381be extends \Symfony\Component\DependencyInjection\Tests\Compiler\Wither implements \Symfony\Component\VarExporter\LazyObjectInterface
77+
{
78+
use \Symfony\Component\VarExporter\LazyProxyTrait;
79+
80+
private const LAZY_OBJECT_PROPERTY_SCOPES = [
81+
'foo' => [parent::class, 'foo', null],
82+
];
83+
}
84+
85+
// Help opcache.preload discover always-needed symbols
86+
class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class);
87+
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class);
88+
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);

src/Symfony/Component/ErrorHandler/Debug.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public static function enable(): ErrorHandler
3131

3232
@ini_set('zend.assertions', 1);
3333
ini_set('assert.active', 1);
34-
ini_set('assert.warning', 0);
3534
ini_set('assert.exception', 1);
3635

3736
DebugClassLoader::enable();

src/Symfony/Component/ErrorHandler/Tests/ErrorHandlerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ public function testAssertQuietEval()
619619
$this->markTestSkipped('zend.assertions is forcibly disabled');
620620
}
621621

622+
set_error_handler(function () {});
622623
$ini = [
623624
ini_set('zend.assertions', 1),
624625
ini_set('assert.active', 1),
@@ -627,6 +628,7 @@ public function testAssertQuietEval()
627628
ini_set('assert.callback', null),
628629
ini_set('assert.exception', 0),
629630
];
631+
restore_error_handler();
630632

631633
$logger = new BufferingLogger();
632634
$handler = new ErrorHandler($logger);

src/Symfony/Component/Runtime/Internal/BasicErrorHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public static function register(bool $debug): void
3232
if (0 <= \ini_get('zend.assertions')) {
3333
ini_set('zend.assertions', 1);
3434
ini_set('assert.active', $debug);
35-
ini_set('assert.warning', 0);
3635
ini_set('assert.exception', 1);
3736
}
3837

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