diff --git a/VariadicController.php b/VariadicController.php new file mode 100644 index 0000000..1f8b380 --- /dev/null +++ b/VariadicController.php @@ -0,0 +1,35 @@ +templating = $templating; + $this->template = $template; + } + + public function __invoke(...$arguments) // PHP 5.6+ + { + // Variadic $arguments apparently not supported when empty by Symfony 3.3.6 ArgumentResolver + // and viewed as a regular array by knplabs/rad-resource-resolver v2.1 + + return new Response($this->templating->render($this->template, $arguments)); + } +} diff --git a/composer.json b/composer.json index b892614..616304b 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "symfony/templating": "^2.0 || ^3.0 || ^4.0" }, "require-dev": { + "php": "^5.6", "symfony/twig-bridge": "^2.0 || ^3.0 || ^4.0", "symfony/var-dumper": "^2.0 || ^3.0 || ^4.0", "twig/twig": "^1.0 || ^2.0" diff --git a/tests/VariadicControllerTest.php b/tests/VariadicControllerTest.php new file mode 100644 index 0000000..d5283da --- /dev/null +++ b/tests/VariadicControllerTest.php @@ -0,0 +1,68 @@ +assertInstanceOf( + // VariadicController::class, // 5.4 < php (code is checked even if not executed!) + 'SymfonyUtil\Controller\VariadicController', + new VariadicController(new TwigEngine( + new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])), + new TemplateNameParser() + )) + ); + } + + public function testEmptyReturnsResponse() + { + $this->assertInstanceOf( + // Response::class, // 5.4 < php (code is checked even if not executed!) + 'Symfony\Component\HttpFoundation\Response', + (new VariadicController(new TwigEngine( + new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])), + new TemplateNameParser() + )))->__invoke() + ); + } + + public function testArrayReturnsResponse() + { + $this->assertInstanceOf( + // Response::class, // 5.4 < php (code is checked even if not executed!) + 'Symfony\Component\HttpFoundation\Response', + (new VariadicController(new TwigEngine( + new Twig_Environment(new Twig_Loader_Array([ + 'index.html.twig' => '