| @@ 17-35 (lines=19) @@ | ||
| 14 | use Symfony\Component\HttpFoundation\Response; |
|
| 15 | use Symfony\Component\Templating\EngineInterface; |
|
| 16 | ||
| 17 | class VariadicController |
|
| 18 | { |
|
| 19 | protected $templating; |
|
| 20 | protected $template; |
|
| 21 | ||
| 22 | public function __construct(EngineInterface $templating, $template = 'index.html.twig') |
|
| 23 | { |
|
| 24 | $this->templating = $templating; |
|
| 25 | $this->template = $template; |
|
| 26 | } |
|
| 27 | ||
| 28 | public function __invoke(...$arguments) // PHP 5.6+ |
|
| 29 | { |
|
| 30 | // Variadic $arguments apparently not supported when empty by Symfony 3.3.6 ArgumentResolver |
|
| 31 | // and viewed as a regular array by knplabs/rad-resource-resolver v2.1 |
|
| 32 | ||
| 33 | return new Response($this->templating->render($this->template, $arguments)); |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||
| @@ 17-33 (lines=17) @@ | ||
| 14 | use Symfony\Component\HttpFoundation\Response; |
|
| 15 | use Symfony\Component\Templating\EngineInterface; |
|
| 16 | ||
| 17 | class TemplatingController |
|
| 18 | { |
|
| 19 | const TEMPLATE = 'index.html.twig'; |
|
| 20 | protected $templating; |
|
| 21 | protected $template; |
|
| 22 | ||
| 23 | public function __construct(EngineInterface $templating, $template = self::TEMPLATE) |
|
| 24 | { |
|
| 25 | $this->templating = $templating; |
|
| 26 | $this->template = $template; |
|
| 27 | } |
|
| 28 | ||
| 29 | public function __invoke() |
|
| 30 | { |
|
| 31 | return new Response($this->templating->render($this->template)); |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||