MariaCore/example/app/Controller/HelloController.php

39 lines
849 B
PHP

<?php
namespace App\Controller;
use MyCodebox\MariaCore\Http\Request;
use MyCodebox\MariaCore\Http\Response;
use Twig\Environment;
/**
* Beispiel-Controller für Begrüßungen.
*/
class HelloController
{
protected Environment $twig;
/**
* Konstruktor mit Twig-Dependency.
*
* @param Environment $twig
*/
public function __construct(Environment $twig)
{
$this->twig = $twig;
}
/**
* Gibt eine HTML-Begrüßung mit Twig-Template zurück.
*
* @param Request $request
* @param array $params
* @return Response
*/
public function greet(Request $request, array $params): Response
{
$name = $params['name'] ?? 'Gast';
$html = $this->twig->render('hello.html.twig', ['name' => $name]);
return (new Response())->withHtml($html);
}
}