Revert "feature #36184 [FrameworkBundle] Deprecate renderView() in favor of renderTemplate() (javiereguiluz)"
This reverts commitb494beb5dc
, reversing changes made tob9d41490fe
.
This commit is contained in:
parent
3e737ec28f
commit
ad01068b38
|
@ -54,7 +54,6 @@ FrameworkBundle
|
||||||
* Deprecated passing a `RouteCollectionBuilder` to `MicroKernelTrait::configureRoutes()`, type-hint `RoutingConfigurator` instead
|
* 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 *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 `session.attribute_bag` service and `session.flash_bag` service.
|
||||||
* Deprecated the `AbstractController::renderView()` method in favor of `AbstractController::renderTemplate()`
|
|
||||||
|
|
||||||
HttpFoundation
|
HttpFoundation
|
||||||
--------------
|
--------------
|
||||||
|
|
|
@ -239,34 +239,22 @@ abstract class AbstractController implements ServiceSubscriberInterface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a rendered view.
|
* Returns a rendered view.
|
||||||
*
|
|
||||||
* @deprecated since Symfony 5.1, use renderTemplate() instead.
|
|
||||||
*/
|
*/
|
||||||
protected function renderView(string $view, array $parameters = []): string
|
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')) {
|
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) {
|
if (null === $response) {
|
||||||
$response = new 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')) {
|
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".');
|
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');
|
$twig = $this->container->get('twig');
|
||||||
|
|
||||||
$callback = function () use ($twig, $templatePath, $parameters) {
|
$callback = function () use ($twig, $view, $parameters) {
|
||||||
$twig->display($templatePath, $parameters);
|
$twig->display($view, $parameters);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (null === $response) {
|
if (null === $response) {
|
||||||
|
|
|
@ -369,7 +369,7 @@ class AbstractControllerTest extends TestCase
|
||||||
$controller->denyAccessUnlessGranted('foo');
|
$controller->denyAccessUnlessGranted('foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRenderTemplateTwig()
|
public function testRenderViewTwig()
|
||||||
{
|
{
|
||||||
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
|
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
|
||||||
$twig->expects($this->once())->method('render')->willReturn('bar');
|
$twig->expects($this->once())->method('render')->willReturn('bar');
|
||||||
|
@ -380,7 +380,7 @@ class AbstractControllerTest extends TestCase
|
||||||
$controller = $this->createController();
|
$controller = $this->createController();
|
||||||
$controller->setContainer($container);
|
$controller->setContainer($container);
|
||||||
|
|
||||||
$this->assertEquals('bar', $controller->renderTemplate('foo'));
|
$this->assertEquals('bar', $controller->renderView('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRenderTwig()
|
public function testRenderTwig()
|
||||||
|
|
Reference in New Issue