Skip to content

Commit bc48341

Browse files
Merge branch '7.4' into 8.0
* 7.4: [FrameworkBundle] Dump all registered extensions’ configuration reference fix merge Mark FormFlow as finished if the last step is skipped [HttpKernel] Fix using MapRequestPayload on nullable arguments [ObjectMapper] bypass lazy ghost with class transform [WebProfilerBundle] fix displaying runner [DependencyInjection] Fix preloading LazyClosure [Emoji] Update list to version 17 make doLoadClassMetadata() methods private fix routing config type information [HttpClient] Don't reset unused clients in data collector
2 parents 56432ff + ed9f4e9 commit bc48341

File tree

3 files changed

+64
-17
lines changed

3 files changed

+64
-17
lines changed

DependencyInjection/Compiler/PhpConfigReferenceDumpPass.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,24 @@ class PhpConfigReferenceDumpPass implements CompilerPassInterface
3535
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
3636
3737
{APP_TYPES}
38-
final class App extends AppReference
38+
final class App
3939
{
4040
{APP_PARAM}
4141
public static function config(array $config): array
4242
{
43-
return parent::config($config);
43+
return AppReference::config($config);
4444
}
4545
}
4646
4747
namespace Symfony\Component\Routing\Loader\Configurator;
4848
4949
{ROUTES_TYPES}
50-
final class Routes extends RoutesReference
50+
final class Routes
5151
{
5252
{ROUTES_PARAM}
5353
public static function config(array $config): array
5454
{
55-
return parent::config($config);
55+
return $config;
5656
}
5757
}
5858

@@ -95,6 +95,15 @@ public function process(ContainerBuilder $container): void
9595
$appTypes = '';
9696

9797
$anyEnvExtensions = [];
98+
foreach ($container->getExtensions() as $alias => $extension) {
99+
if (!$configuration = $this->getConfiguration($extension, $container)) {
100+
continue;
101+
}
102+
103+
$anyEnvExtensions[$alias] = $extension;
104+
$type = $this->camelCase($alias).'Config';
105+
$appTypes .= \sprintf("\n * @psalm-type %s = %s", $type, ArrayShapeGenerator::generate($configuration->getConfigTreeBuilder()->buildTree()));
106+
}
98107
foreach ($this->bundlesDefinition as $bundle => $envs) {
99108
if (!is_subclass_of($bundle, BundleInterface::class)) {
100109
continue;
@@ -105,15 +114,21 @@ public function process(ContainerBuilder $container): void
105114
if (!$configuration = $this->getConfiguration($extension, $container)) {
106115
continue;
107116
}
108-
$anyEnvExtensions[$bundle] = $extension;
109-
$type = $this->camelCase($extension->getAlias()).'Config';
110-
$appTypes .= \sprintf("\n * @psalm-type %s = %s", $type, ArrayShapeGenerator::generate($configuration->getConfigTreeBuilder()->buildTree()));
117+
118+
$extensionAlias = $extension->getAlias();
119+
if (isset($anyEnvExtensions[$extensionAlias])) {
120+
$extension = $anyEnvExtensions[$extensionAlias];
121+
} else {
122+
$anyEnvExtensions[$extensionAlias] = $extension;
123+
$type = $this->camelCase($extensionAlias).'Config';
124+
$appTypes .= \sprintf("\n * @psalm-type %s = %s", $type, ArrayShapeGenerator::generate($configuration->getConfigTreeBuilder()->buildTree()));
125+
}
111126

112127
foreach ($knownEnvs as $env) {
113128
if ($envs[$env] ?? $envs['all'] ?? false) {
114129
$extensionsPerEnv[$env][] = $extension;
115130
} else {
116-
unset($anyEnvExtensions[$bundle]);
131+
unset($anyEnvExtensions[$extensionAlias]);
117132
}
118133
}
119134
}

Tests/DependencyInjection/Compiler/PhpConfigReferenceDumpPassTest.php

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testProcessWithConfigDir()
7171

7272
$content = file_get_contents($referenceFile);
7373
$this->assertStringContainsString('namespace Symfony\Component\DependencyInjection\Loader\Configurator;', $content);
74-
$this->assertStringContainsString('final class App extends AppReference', $content);
74+
$this->assertStringContainsString('final class App', $content);
7575
$this->assertStringContainsString('public static function config(array $config): array', $content);
7676
$this->assertEquals([new FileResource(realpath($this->tempDir).'/reference.php')], $container->getResources());
7777
}
@@ -95,8 +95,8 @@ public function testProcessGeneratesExpectedReferenceFile()
9595
$container = new ContainerBuilder();
9696
$container->setParameter('.container.known_envs', ['dev', 'prod', 'test']);
9797

98-
$extension = new TestExtension();
99-
$container->registerExtension($extension);
98+
$container->registerExtension(new TestExtension(false));
99+
$container->registerExtension(new AppExtension());
100100

101101
$pass = new PhpConfigReferenceDumpPass($this->tempDir.'/reference.php', [
102102
TestBundle::class => ['all' => true],
@@ -133,12 +133,16 @@ class TestBundle extends Bundle
133133
{
134134
public function getContainerExtension(): ?ExtensionInterface
135135
{
136-
return new TestExtension();
136+
return new TestExtension(true);
137137
}
138138
}
139139

140140
class TestExtension extends Extension
141141
{
142+
public function __construct(private bool $fromBundle)
143+
{
144+
}
145+
142146
public function load(array $configs, ContainerBuilder $container): void
143147
{
144148
}
@@ -160,12 +164,16 @@ public function getAlias(): string
160164

161165
public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface
162166
{
163-
return new TestConfiguration();
167+
return new TestConfiguration($this->fromBundle);
164168
}
165169
}
166170

167171
class TestConfiguration implements ConfigurationInterface
168172
{
173+
public function __construct(private bool $fromBundle)
174+
{
175+
}
176+
169177
public function getConfigTreeBuilder(): TreeBuilder
170178
{
171179
$treeBuilder = new TreeBuilder('test');
@@ -181,9 +189,30 @@ public function getConfigTreeBuilder(): TreeBuilder
181189
->integerNode('count')->end()
182190
->end()
183191
->end()
192+
->booleanNode('fromBundle')->defaultValue($this->fromBundle)->end()
184193
->end();
185194
}
186195

187196
return $treeBuilder;
188197
}
189198
}
199+
200+
class AppExtension extends Extension
201+
{
202+
public function load(array $configs, ContainerBuilder $container): void
203+
{
204+
}
205+
206+
public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface
207+
{
208+
return new AppConfiguration();
209+
}
210+
}
211+
212+
class AppConfiguration implements ConfigurationInterface
213+
{
214+
public function getConfigTreeBuilder(): TreeBuilder
215+
{
216+
return new TreeBuilder('app', 'boolean');
217+
}
218+
}

Tests/Fixtures/reference.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,15 @@
129129
* name?: scalar|null,
130130
* count?: int,
131131
* },
132+
* fromBundle?: bool, // Default: false
132133
* }
134+
* @psalm-type AppConfig = bool
133135
* @psalm-type ConfigType = array{
134136
* imports?: ImportsConfig,
135137
* parameters?: ParametersConfig,
136138
* services?: ServicesConfig,
137139
* test?: TestConfig,
140+
* app?: AppConfig,
138141
* "when@dev"?: array{
139142
* imports?: ImportsConfig,
140143
* parameters?: ParametersConfig,
@@ -161,7 +164,7 @@
161164
* }>
162165
* }
163166
*/
164-
final class App extends AppReference
167+
final class App
165168
{
166169
/**
167170
* @param ConfigType $config
@@ -170,7 +173,7 @@ final class App extends AppReference
170173
*/
171174
public static function config(array $config): array
172175
{
173-
return parent::config($config);
176+
return AppReference::config($config);
174177
}
175178
}
176179

@@ -238,7 +241,7 @@ public static function config(array $config): array
238241
* ...<string, RouteConfig|ImportConfig|AliasConfig>
239242
* }
240243
*/
241-
final class Routes extends RoutesReference
244+
final class Routes
242245
{
243246
/**
244247
* @param RoutesConfig $config
@@ -247,6 +250,6 @@ final class Routes extends RoutesReference
247250
*/
248251
public static function config(array $config): array
249252
{
250-
return parent::config($config);
253+
return $config;
251254
}
252255
}

0 commit comments

Comments
 (0)