9
9
use Symfony \Component \HttpFoundation \Request ;
10
10
use Symfony \Component \HttpFoundation \Response ;
11
11
use Symfony \Component \Routing \Annotation \Route ;
12
+ use Symfony \Contracts \Translation \TranslatorInterface ;
12
13
13
14
class SuggestLocationController extends AbstractController
14
15
{
15
16
private LoggerInterface $ logger ;
17
+ private TranslatorInterface $ translator ;
16
18
17
- public function __construct (LoggerInterface $ logger )
19
+ public function __construct (LoggerInterface $ logger, TranslatorInterface $ translator )
18
20
{
19
21
$ this ->logger = $ logger ;
22
+ $ this ->translator = $ translator ;
20
23
}
21
24
22
25
/**
@@ -27,7 +30,7 @@ public function suggestExactPlaces(Request $request, SuggestLocationModel $model
27
30
$ response = new JsonResponse ();
28
31
$ searchTerm = $ request ->query ->get ('term ' , '' );
29
32
30
- $ this ->logger -> alert ( " Search term: { $ searchTerm}" );
33
+ $ this ->logSearchInfo ( __METHOD__ , $ searchTerm );
31
34
32
35
$ result = $ model ->getSuggestionsForPlacesExact ($ searchTerm );
33
36
$ response ->setData ($ result );
@@ -43,7 +46,7 @@ public function suggestPlaces(Request $request, SuggestLocationModel $model): Js
43
46
$ response = new JsonResponse ();
44
47
$ searchTerm = $ request ->query ->get ('term ' , '' );
45
48
46
- $ this ->logger -> alert ( " Search term: { $ searchTerm}" );
49
+ $ this ->logSearchInfo ( __METHOD__ , $ searchTerm );
47
50
48
51
$ result = $ model ->getSuggestionsForPlaces ($ searchTerm );
49
52
$ response ->setData ($ result );
@@ -62,11 +65,16 @@ public function suggestLocations(Request $request, SuggestLocationModel $model):
62
65
$ response = new JsonResponse ();
63
66
$ searchTerm = $ request ->query ->get ('term ' , '' );
64
67
65
- $ this ->logger -> alert ( " Search term: { $ searchTerm}" );
68
+ $ this ->logSearchInfo ( __METHOD__ , $ searchTerm );
66
69
67
70
$ result = $ model ->getSuggestionsForLocations ($ searchTerm );
68
71
$ response ->setData ($ result );
69
72
70
73
return $ response ;
71
74
}
75
+
76
+ private function logSearchInfo (string $ function , string $ searchTerm )
77
+ {
78
+ $ this ->logger ->alert ($ function , ['locale ' => $ this ->translator ->getLocale (), 'searchTerm ' => $ searchTerm ]);
79
+ }
72
80
}
0 commit comments