10000 [FrameworkBundle] Deprecate renderView() in favor of renderTemplate() by javiereguiluz · Pull Request #36184 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Deprecate renderView() in favor of renderTemplate() #36184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADE-5.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ FrameworkBundle
* Deprecated passing a `RouteCollectionBuilder` to `MicroKernelTrait::configureRoutes()`, type-hint `RoutingConfigurator` instead
* Deprecated *not* setting the "framework.router.utf8" configuration option as it will default to `true` in Symfony 6.0
* Deprecated `session.attribute_bag` service and `session.flash_bag` service.
* Deprecated the `AbstractController::renderView()` method in favor of `AbstractController::renderTemplate()`

HttpFoundation
--------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,22 +239,34 @@ protected function denyAccessUnlessGranted($attributes, $subject = null, string

/**
* Returns a rendered view.
*
* @deprecated since Symfony 5.1, use renderTemplate() instead.
*/
protected function renderView(string $view, array $parameters = []): string
{
trigger_deprecation('symfony/framework-bundle', '5.1', 'The "%s" method is deprecated, use "renderTemplate()" instead.', __METHOD__);

return $this->renderTemplate($view, $parameters);
}

/**
* Returns a rendered template.
*/
protected function renderTemplate(string $templateName, array $parameters = []): string
{
if (!$this->container->has('twig')) {
throw new \LogicException('You can not use the "renderView" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
throw new \LogicException('You can not use the "renderTemplate()" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
}

return $this->container->get('twig')->render($view, $parameters);
return $this->container->get('twig')->render($templateName, $parameters);
}

/**
* Renders a view.
* Renders a template.
*/
protected function render(string $view, array $parameters = [], Response $response = null): Response
protected function render(string $templateName, array $parameters = [], Response $response = null): Response
{
$content = $this->renderView($view, $parameters);
$content = $this->renderTemplate($templateName, $parameters);

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

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

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

$callback = function () use ($twig, $view, $parameters) {
$twig->display($view, $parameters);
$callback = function () use ($twig, $templatePath, $parameters) {
$twig->display($templatePath, $parameters);
};

if (null === $response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function testdenyAccessUnlessGranted()
$controller->denyAccessUnlessGranted('foo');
}

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

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

public function testRenderTwig()
Expand Down
0