8000 [FrameworkBundle] Deprecate renderView() in favor of renderTemplate() · symfony/symfony@7b9ff2a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b9ff2a

Browse files
javiereguiluzfabpot
authored andcommitted
[FrameworkBundle] Deprecate renderView() in favor of renderTemplate()
1 parent b9d4149 commit 7b9ff2a

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

UPGRADE-5.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ FrameworkBundle
5454
* Deprecated passing a `RouteCollectionBuilder` to `MicroKernelTrait::configureRoutes()`, type-hint `RoutingConfigurator` instead
5555
* Deprecated *not* setting the "framework.router.utf8" configuration option as it will default to `true` in Symfony 6.0
5656
* Deprecated `session.attribute_bag` service and `session.flash_bag` service.
57+
* Deprecated the `AbstractController::renderView()` method in favor of `AbstractController::renderTemplate()`
5758

5859
HttpFoundation
5960
--------------

src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

+21Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,34 @@ protected function denyAccessUnlessGranted($attributes, $subject = null, string
239239

240240
/**
241241
* Returns a rendered view.
242+
*
243+
* @deprecated since Symfony 5.1, use renderTemplate() instead.
242244
*/
243245
protected function renderView(string $view, array $parameters = []): string
246+
{
247+
trigger_deprecation('symfony/framework-bundle', '5.1', 'The "%s" method is deprecated, use "renderTemplate()" instead.', __METHOD__);
248+
249+
return $this->renderTemplate($view, $parameters);
250+
}
251+
252+
/**
253+
* Returns a rendered template.
254+
*/
255+
protected function renderTemplate(string $templateName, array $parameters = []): string
244256
{
245257
if (!$this->container->has('twig')) {
246-
throw new \LogicException('You can not use the "renderView" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
258+
throw new \LogicException('You can not use the "renderTemplate()" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
247259
}
248260

249-
return $this->container->get('twig')->render($view, $parameters);
261+
return $this->container->get('twig')->render($templateName, $parameters);
250262
}
251263

252264
/**
253-
* Renders a view.
265+
* Renders a template.
254266
*/
255-
protected function render(string $view, array $parameters = [], Response $response = null): Response
267+
protected function render(string $templateName, array $parameters = [], Response $response = null): Response
256268
{
257-
$content = $this->renderView($view, $parameters);
269+
$content = $this->renderTemplate($templateName, $parameters);
258270

259271
if (null === $response) {
260272
$response = new Response();
@@ -266,18 +278,18 @@ protected function render(string $view, array $parameters = [], Response $respon
266278
}
267279

268280
/**
269-
* Streams a view.
281+
* Streams a template.
270282
*/
271-
protected function stream(string $view, array $parameters = [], StreamedResponse $response = null): StreamedResponse
283+
protected function stream(string $templatePath, array $parameters = [], StreamedResponse $response = null): StreamedResponse
272284
{
273285
if (!$this->container->has('twig')) {
274286
throw new \LogicException('You can not use the "stream" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
275287
}
276288

277289
$twig = $this->container->get('twig');
278290

279-
$callback = function () use ($twig, $view, $parameters) {
280-
$twig->display($view, $parameters);
291+
$callback = function () use ($twig, $templatePath, $parameters) {
292+
$twig->display($templatePath, $parameters);
281293
};
282294

283295
if (null === $response) {

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public function testdenyAccessUnlessGranted()
369369
$controller->denyAccessUnlessGranted('foo');
370370
}
371371

372-
public function testRenderViewTwig()
372+
public function testRenderTemplateTwig()
373373
{
374374
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
375375
$twig->expects($this->once())->method('render')->willReturn('bar');
@@ -380,7 +380,7 @@ public function testRenderViewTwig()
380380
$controller = $this->createController();
381381
$controller->setContainer($container);
382382

383-
$this->assertEquals('bar', $controller->renderView('foo'));
383+
$this->assertEquals('bar', $controller->renderTemplate('foo'));
384384
}
385385

386386
public function testRenderTwig()
< 3885 /td>

0 commit comments

Comments
 (0)
0