diff --git a/config/services.yaml b/config/services.yaml index f43615c..8b81a90 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -18,8 +18,8 @@ services: autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. bind: # bind examples - #string $environment: '%kernel.environment%' - #string $debug: '%kernel.debug%' + string $environment: '%kernel.environment%' + bool $debug: '%kernel.debug%' # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name diff --git a/src/Controller/HelloWorldAction.php b/src/Controller/HelloWorldAction.php index 458e5bc..dc6a22e 100644 --- a/src/Controller/HelloWorldAction.php +++ b/src/Controller/HelloWorldAction.php @@ -11,6 +11,8 @@ use Symfony\Component\Routing\Attribute\Route; /** + * We use the two binds we have defined in config/services.yaml. + * * @see HelloWorldTest */ #[AsController] @@ -18,8 +20,11 @@ final class HelloWorldAction extends AbstractController { #[Route(path: '/hello-world', name: self::class)] - public function __invoke(): Response + public function __invoke(string $environment, bool $debug): Response { - return $this->render(self::class.'.html.twig'); + return $this->render(self::class.'.html.twig', [ + 'environment' => $environment, + 'debug' => $debug, + ]); } } diff --git a/templates/App/Controller/HelloWorldAction.html.twig b/templates/App/Controller/HelloWorldAction.html.twig index 6f94974..c184db5 100644 --- a/templates/App/Controller/HelloWorldAction.html.twig +++ b/templates/App/Controller/HelloWorldAction.html.twig @@ -7,4 +7,12 @@
This a simple hello world page without any heavy process. Just a basic Twig template rendering.
+ +These two parameters are injected in the controller action thanks to services binds.
+ (@see config/services.yaml
)