Skip to content

Commit 6fae4ea

Browse files
Merge branch '6.4' into 7.0
* 6.4: [FrameworkBundle] Deprecate not setting both `framework.session.save_path` and `framework.session.handler_id` at the same time [Translation] add @welcoMattic as codeowner [FrameworkBundle] Add `AbstractController::renderBlock()` and `renderBlockView()` [Clock] Add $modifier argument to now() helper
2 parents f991f32 + 405cd3c commit 6fae4ea

File tree

3 files changed

+72
-27
lines changed

3 files changed

+72
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CHANGELOG
1818
6.4
1919
---
2020

21+
* Add `AbstractController::renderBlock()` and `renderBlockView()`
2122
* Add native return type to `Translator` and to `Application::reset()`
2223
* Deprecate the integration of Doctrine annotations, either uninstall the `doctrine/annotations` package or disable the integration by setting `framework.annotations` to `false`
2324
* Enable `json_decode_detailed_errors` context for Serializer by default if `kernel.debug` is true and the `seld/jsonlint` package is installed
@@ -31,6 +32,7 @@ CHANGELOG
3132
* Deprecate not setting the `framework.session.cookie_secure` config option; it will default to `auto` in 7.0
3233
* Deprecate not setting the `framework.session.cookie_samesite` config option; it will default to `lax` in 7.0
3334
* Deprecate not setting the `framework.session.handler_id` config option; it will default to `session.handler.native_file` when `framework.session.save_path` is set or `null` otherwise in 7.0
35+
* Deprecate not setting the `framework.session.save_path` config option when `framework.session.handler_id` is not set; it will default to `null` in 7.0
3436
* Deprecate not setting the `framework.uid.default_uuid_version` config option; it will default to `7` in 7.0
3537
* Deprecate not setting the `framework.uid.time_based_uuid_version` config option; it will default to `7` in 7.0
3638
* Deprecate not setting the `framework.validation.email_validation_mode` config option; it will default to `html5` in 7.0

Controller/AbstractController.php

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,17 @@ protected function denyAccessUnlessGranted(mixed $attribute, mixed $subject = nu
226226
*/
227227
protected function renderView(string $view, array $parameters = []): string
228228
{
229-
if (!$this->container->has('twig')) {
230-
throw new \LogicException('You cannot use the "renderView" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
231-
}
232-
233-
foreach ($parameters as $k => $v) {
234-
if ($v instanceof FormInterface) {
235-
$parameters[$k] = $v->createView();
236-
}
237-
}
229+
return $this->doRenderView($view, null, $parameters, __FUNCTION__);
230+
}
238231

239-
return $this->container->get('twig')->render($view, $parameters);
232+
/**
233+
* Returns a rendered block from a view.
234+
*
235+
* Forms found in parameters are auto-cast to form views.
236+
*/
237+
protected function renderBlockView(string $view, string $block, array $parameters = []): string
238+
{
239+
return $this->doRenderView($view, $block, $parameters, __FUNCTION__);
240240
}
241241

242242
/**
@@ -247,21 +247,18 @@ protected function renderView(string $view, array $parameters = []): string
247247
*/
248248
protected function render(string $view, array $parameters = [], Response $response = null): Response
249249
{
250-
$content = $this->renderView($view, $parameters);
251-
$response ??= new Response();
252-
253-
if (200 === $response->getStatusCode()) {
254-
foreach ($parameters as $v) {
255-
if ($v instanceof FormInterface && $v->isSubmitted() && !$v->isValid()) {
256-
$response->setStatusCode(422);
257-
break;
258-
}
259-
}
260-
}
261-
262-
$response->setContent($content);
250+
return $this->doRender($view, null, $parameters, $response, __FUNCTION__);
251+
}
263252

264-
return $response;
253+
/**
254+
* Renders a block in a view.
255+
*
256+
* If an invalid form is found in the list of parameters, a 422 status code is returned.
257+
* Forms found in parameters are auto-cast to form views.
258+
*/
259+
protected function renderBlock(string $view, string $block, array $parameters = [], Response $response = null): Response
260+
{
261+
return $this->doRender($view, $block, $parameters, $response, __FUNCTION__);
265262
}
266263

267264
/**
@@ -414,4 +411,42 @@ protected function sendEarlyHints(iterable $links = [], Response $response = nul
414411

415412
return $response;
416413
}
414+
415+
private function doRenderView(string $view, ?string $block, array $parameters, string $method): string
416+
{
417+
if (!$this->container->has('twig')) {
418+
throw new \LogicException(sprintf('You cannot use the "%s" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".', $method));
419+
}
420+
421+
foreach ($parameters as $k => $v) {
422+
if ($v instanceof FormInterface) {
423+
$parameters[$k] = $v->createView();
424+
}
425+
}
426+
427+
if (null !== $block) {
428+
return $this->container->get('twig')->load($view)->renderBlock($block, $parameters);
429+
}
430+
431+
return $this->container->get('twig')->render($view, $parameters);
432+
}
433+
434+
private function doRender(string $view, ?string $block, array $parameters, ?Response $response, string $method): Response
435+
{
436+
$content = $this->doRenderView($view, $block, $parameters, $method);
437+
$response ??= new Response();
438+
439+
if (200 === $response->getStatusCode()) {
440+
foreach ($parameters as $v) {
441+
if ($v instanceof FormInterface && $v->isSubmitted() && !$v->isValid()) {
442+
$response->setStatusCode(422);
443+
break;
444+
}
445+
}
446+
}
447+
448+
$response->setContent($content);
449+
450+
return $response;
451+
}
417452
}

DependencyInjection/Configuration.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,19 @@ private function addSessionSection(ArrayNodeDefinition $rootNode): void
661661
}
662662

663663
if (!\array_key_exists('handler_id', $v['session'])) {
664-
trigger_deprecation('symfony/framework-bundle', '6.4', 'Not setting the "framework.session.handler_id" config option is deprecated. It will default to "session.handler.native_file" when "framework.session.save_path" is set or "null" otherwise in 7.0.');
664+
if (!\array_key_exists('save_path', $v['session'])) {
665+
trigger_deprecation('symfony/framework-bundle', '6.4', 'Not setting the "framework.session.save_path" config option when the "framework.session.handler_id" config option is not set either is deprecated. Both options will default to "null" in 7.0.');
666+
} else {
667+
trigger_deprecation('symfony/framework-bundle', '6.4', 'Not setting the "framework.session.handler_id" config option is deprecated. It will default to "session.handler.native_file" when "framework.session.save_path" is set or "null" otherwise in 7.0.');
668+
}
665669
}
666670
}
667671

668-
$v['session'] += ['cookie_samesite' => null, 'handler_id' => 'session.handler.native_file'];
672+
$v['session'] += [
673+
'cookie_samesite' => null,
674+
'handler_id' => 'session.handler.native_file',
675+
'save_path' => '%kernel.cache_dir%/sessions',
676+
];
669677

670678
return $v;
671679
})
@@ -697,7 +705,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode): void
697705
->scalarNode('gc_divisor')->end()
698706
->scalarNode('gc_probability')->defaultValue(1)->end()
699707
->scalarNode('gc_maxlifetime')->end()
700-
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
708+
->scalarNode('save_path')->end()
701709
->integerNode('metadata_update_threshold')
702710
->defaultValue(0)
703711
->info('seconds to wait between 2 session metadata updates')

0 commit comments

Comments
 (0)