Skip to content

Commit

Permalink
chore: use MapQueryParameter attribute instead of the request service
Browse files Browse the repository at this point in the history
  • Loading branch information
COil committed Jan 1, 2025
1 parent e35570e commit 313d943
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Controller/SlugifyAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use App\Helper\StringHelper;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
use Symfony\Component\Routing\Attribute\Route;

/**
Expand All @@ -22,14 +22,15 @@ final class SlugifyAction extends AbstractController
{
/**
* Simple API endpoint returning JSON. For a more serious API, please use API Platform 🕸.
* We can use the MapQueryParameter attribute to inject GET parameters.
*
* @see https://api-platform.com/
*/
#[Route(path: '/api/slugify', name: self::class)]
public function __invoke(Request $request, StringHelper $stringHelper): Response
{
return $this->json([
'slug' => $stringHelper->slugify($request->query->getString('title')),
]);
public function __invoke(
StringHelper $stringHelper,
#[MapQueryParameter] string $title,
): Response {
return $this->json(['slug' => $stringHelper->slugify($title)]);
}
}

0 comments on commit 313d943

Please sign in to comment.