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 8e7eac6

Browse filesBrowse files
committed
feature #24637 [FrameworkBundle] Improve the DX of TemplateController when using SF 4 (dunglas)
This PR was merged into the 4.1-dev branch. Discussion ---------- [FrameworkBundle] Improve the DX of TemplateController when using SF 4 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Tiny DX improvement when using modern Symfony. Allow to write: ```yaml # config/routes.yaml index: path: / defaults: _controller: 'Symfony\Bundle\FrameworkBundle\Controller\TemplateController' template: 'homepage.html.twig' ``` Instead of: ```yaml index: path: / defaults: _controller: 'Symfony\Bundle\FrameworkBundle\Controller\TemplateController::templateAction' template: 'homepage.html.twig' ``` I was thinking about doing the same for `RedirectController`, but it's not that easy because it contains two methods. Commits ------- 6d15055 [FrameworkBundle] Improve the DX of TemplateController when using SF 4
2 parents a603ba0 + 6d15055 commit 8e7eac6
Copy full SHA for 8e7eac6

File tree

2 files changed

+10
-2
lines changed
Filter options

2 files changed

+10
-2
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ public function templateAction(string $template, int $maxAge = null, int $shared
6767

6868
return $response;
6969
}
70+
71+
public function __invoke(string $template, int $maxAge = null, int $sharedAge = null, bool $private = null): Response
72+
{
73+
return $this->templateAction($template, $maxAge, $sharedAge, $private);
74+
}
7075
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TemplateControllerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TemplateControllerTest.php
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@ class TemplateControllerTest extends TestCase
2323
public function testTwig()
2424
{
2525
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
26-
$twig->expects($this->once())->method('render')->willReturn('bar');
26+
$twig->expects($this->exactly(2))->method('render')->willReturn('bar');
2727

2828
$controller = new TemplateController($twig);
2929

3030
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
31+
$this->assertEquals('bar', $controller('mytemplate')->getContent());
3132
}
3233

3334
public function testTemplating()
3435
{
3536
$templating = $this->getMockBuilder(EngineInterface::class)->getMock();
36-
$templating->expects($this->once())->method('render')->willReturn('bar');
37+
$templating->expects($this->exactly(2))->method('render')->willReturn('bar');
3738

3839
$controller = new TemplateController(null, $templating);
3940

4041
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
42+
$this->assertEquals('bar', $controller('mytemplate')->getContent());
4143
}
4244

4345
/**
@@ -49,5 +51,6 @@ public function testNoTwigNorTemplating()
4951
$controller = new TemplateController();
5052

5153
$controller->templateAction('mytemplate')->getContent();
54+
$controller('mytemplate')->getContent();
5255
}
5356
}

0 commit comments

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