37 lines
1008 B
PHP
37 lines
1008 B
PHP
<?php
|
|
|
|
namespace App\Application\Controller;
|
|
|
|
use App\Domain\Search\Engine;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
class SearchController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly Engine $engine,
|
|
) {
|
|
}
|
|
|
|
#[Route('/s/{query}', name: 'search')]
|
|
public function index(string $query): Response
|
|
{
|
|
$decodedQuery = urldecode($query);
|
|
|
|
return $this->render('result/index.html.twig', [
|
|
'tiles' => $this->engine->search($decodedQuery)->array(),
|
|
'query' => $decodedQuery,
|
|
]);
|
|
}
|
|
|
|
#[Route('/result/{query}', name: 'result')]
|
|
public function result(string $query): Response
|
|
{
|
|
$decodedQuery = urldecode($query);
|
|
|
|
return $this->render('_components/result.html.twig', [
|
|
'tiles' => $this->engine->search($decodedQuery)->array(),
|
|
]);
|
|
}
|
|
} |