diff --git a/UPGRADE-5.1.md b/UPGRADE-5.1.md index f9384e2942..b575964e0b 100644 --- a/UPGRADE-5.1.md +++ b/UPGRADE-5.1.md @@ -54,7 +54,6 @@ 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 -------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php index d063df1a5b..343c2bbaf5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php @@ -239,34 +239,22 @@ abstract class AbstractController implements ServiceSubscriberInterface /** * 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 "renderTemplate()" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".'); + throw new \LogicException('You can not use the "renderView" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".'); } - return $this->container->get('twig')->render($templateName, $parameters); + return $this->container->get('twig')->render($view, $parameters); } /** - * Renders a template. + * Renders a view. */ - protected function render(string $templateName, array $parameters = [], Response $response = null): Response + protected function render(string $view, array $parameters = [], Response $response = null): Response { - $content = $this->renderTemplate($templateName, $parameters); + $content = $this->renderView($view, $parameters); if (null === $response) { $response = new Response(); @@ -278,9 +266,9 @@ abstract class AbstractController implements ServiceSubscriberInterface } /** - * Streams a template. + * Streams a view. */ - protected function stream(string $templatePath, array $parameters = [], StreamedResponse $response = null): StreamedResponse + protected function stream(string $view, 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".'); @@ -288,8 +276,8 @@ abstract class AbstractController implements ServiceSubscriberInterface $twig = $this->container->get('twig'); - $callback = function () use ($twig, $templatePath, $parameters) { - $twig->display($templatePath, $parameters); + $callback = function () use ($twig, $view, $parameters) { + $twig->display($view, $parameters); }; if (null === $response) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php index 6966ad14a0..0b30d684d8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php @@ -369,7 +369,7 @@ class AbstractControllerTest extends TestCase $controller->denyAccessUnlessGranted('foo'); } - public function testRenderTemplateTwig() + public function testRenderViewTwig() { $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $twig->expects($this->once())->method('render')->willReturn('bar'); @@ -380,7 +380,7 @@ class AbstractControllerTest extends TestCase $controller = $this->createController(); $controller->setContainer($container); - $this->assertEquals('bar', $controller->renderTemplate('foo')); + $this->assertEquals('bar', $controller->renderView('foo')); } public function testRenderTwig()