Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b494beb

Browse filesBrowse files
committed
feature #36184 [FrameworkBundle] Deprecate renderView() in favor of renderTemplate() (javiereguiluz)
This PR was squashed before being merged into the 5.1-dev branch. Discussion ---------- [FrameworkBundle] Deprecate renderView() in favor of renderTemplate() | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | - | License | MIT | Doc PR | - Commits ------- 7b9ff2a [FrameworkBundle] Deprecate renderView() in favor of renderTemplate()
2 parents b9d4149 + 7b9ff2a commit b494beb
Copy full SHA for b494beb

File tree

3 files changed

+24
-11
lines changed
Filter options

3 files changed

+24
-11
lines changed

‎UPGRADE-5.1.md

Copy file name to clipboardExpand all lines: UPGRADE-5.1.md
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php
+21-9Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php
+2-2Lines 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()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.