Skip to content

Commit

Permalink
feat: activate and use bind examples in a controller
Browse files Browse the repository at this point in the history
  • Loading branch information
COil committed Dec 3, 2024
1 parent a0b67f3 commit d77bf92
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/Controller/HelloWorldAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@
use Symfony\Component\Routing\Attribute\Route;

/**
* We use the two binds we have defined in config/services.yaml.
*
* @see HelloWorldTest
*/
#[AsController]
#[Cache(maxage: 3600, public: true)]
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,
]);
}
}
8 changes: 8 additions & 0 deletions templates/App/Controller/HelloWorldAction.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@

<p>This a simple hello world page without any heavy process.
Just a basic Twig template rendering.</p>

<p>These two parameters are injected in the controller action thanks to services binds.
(@see <code>config/services.yaml</code>)</p>

<ul>
<li>Environment: <b>{{ environment }}</b></li>
<li>debug: <b>{{ debug ? 'true' : 'false' }}</b></li>
</ul>
{% endblock %}

0 comments on commit d77bf92

Please sign in to comment.