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 authored Jan 1, 2025
1 parent e35570e commit 47207ab
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 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,13 @@ 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
public function __invoke(StringHelper $stringHelper, #[MapQueryParameter] string $title): Response
{
return $this->json([
'slug' => $stringHelper->slugify($request->query->getString('title')),
]);
return $this->json(['slug' => $stringHelper->slugify($title)]);
}
}

0 comments on commit 47207ab

Please sign in to comment.