8000 bug #59086 [FrameworkBundle] Make uri_signer lazy and improve error w… · symfony/symfony@f24ac9e · GitHub
[go: up one dir, main page]

Skip to content

Commit f24ac9e

Browse files
committed
bug #59086 [FrameworkBundle] Make uri_signer lazy and improve error when kernel.secret is empty (nicolas-grekas)
This PR was merged into the 7.2 branch. Discussion ---------- [FrameworkBundle] Make uri_signer lazy and improve error when kernel.secret is empty | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Some polishing found while delivering The Fast Track workshop at SymfonyCon Vienna ;) The profiler is currently broken if `APP_SECRET` is empty, and the reason is that the twig extension that provides the `render()` function has a dependency on `uri_signer`. Since this dep is not used by the profiler, this error is a false positive. Making the `uri_signer` service lazy resolves the issue. Before that, I noticed that the error message was sub-optimal, telling about `framework.secret` being unconfigured, while it was (but the env var was not). Commits ------- 8a4e809 [FrameworkBundle] Make uri_signer lazy and improve error when kernel.secret is empty
2 parents 6076b87 + 8a4e809 commit f24ac9e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,17 @@ public function load(array $configs, ContainerBuilder $container): void
310310
}
311311
}
312312

313+
$emptySecretHint = '"framework.secret" option';
313314
if (isset($config['secret'])) {
314315
$container->setParameter('kernel.secret', $config['secret']);
316+
$usedEnvs = [];
317+
$container->resolveEnvPlaceholders($config['secret'], null, $usedEnvs);
318+
319+
if ($usedEnvs) {
320+
$emptySecretHint = \sprintf('"%s" env var%s', implode('", "', $usedEnvs), 1 === \count($usedEnvs) ? '' : 's');
321+
}
315322
}
316-
$container->parameterCannotBeEmpty('kernel.secret', 'A non-empty value for the parameter "kernel.secret" is required. Did you forget to configure the "framework.secret" option?');
323+
$container->parameterCannotBeEmpty('kernel.secret', 'A non-empty value for the parameter "kernel.secret" is required. Did you forget to configure the '.$emptySecretHint.'?');
317324

318325
$container->setParameter('kernel.http_method_override', $config['http_method_override']);
319326
$container->setParameter('kernel.trust_x_sendfile_type_header', $config['trust_x_sendfile_type_header']);

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
157157
->args([
158158
new Parameter('kernel.secret'),
159159
])
160+
->lazy()
160161
->alias(UriSigner::class, 'uri_signer')
161162

162163
->set('config_cache_factory', ResourceCheckerConfigCacheFactory::class)

0 commit comments

Comments
 (0)
0