Skip to content

Commit 47207ab

Browse files
authored
chore: use MapQueryParameter attribute instead of the request service (#151)
1 parent e35570e commit 47207ab

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/Controller/SlugifyAction.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use App\Helper\StringHelper;
88
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9-
use Symfony\Component\HttpFoundation\Request;
109
use Symfony\Component\HttpFoundation\Response;
1110
use Symfony\Component\HttpKernel\Attribute\AsController;
11+
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
1212
use Symfony\Component\Routing\Attribute\Route;
1313

1414
/**
@@ -22,14 +22,13 @@ final class SlugifyAction extends AbstractController
2222
{
2323
/**
2424
* Simple API endpoint returning JSON. For a more serious API, please use API Platform 🕸.
25+
* We can use the MapQueryParameter attribute to inject GET parameters.
2526
*
2627
* @see https://api-platform.com/
2728
*/
2829
#[Route(path: '/api/slugify', name: self::class)]
29-
public function __invoke(Request $request, StringHelper $stringHelper): Response
30+
public function __invoke(StringHelper $stringHelper, #[MapQueryParameter] string $title): Response
3031
{
31-
return $this->json([
32-
'slug' => $stringHelper->slugify($request->query->getString('title')),
33-
]);
32+
return $this->json(['slug' => $stringHelper->slugify($title)]);
3433
}
3534
}

0 commit comments

Comments
 (0)