File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77use App \Helper \StringHelper ;
88use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
9- use Symfony \Component \HttpFoundation \Request ;
109use Symfony \Component \HttpFoundation \Response ;
1110use Symfony \Component \HttpKernel \Attribute \AsController ;
11+ use Symfony \Component \HttpKernel \Attribute \MapQueryParameter ;
1212use 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}
You can’t perform that action at this time.
0 commit comments