66
77use Alpha \VisitorTrackingBundle \Entity \Device ;
88use Alpha \VisitorTrackingBundle \Entity \Session ;
9- use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
9+ use Alpha \VisitorTrackingBundle \Manager \DeviceFingerprintManager ;
10+ use Alpha \VisitorTrackingBundle \Storage \SessionStore ;
11+ use Doctrine \ORM \EntityManager ;
12+ use Psr \Log \LoggerInterface ;
1013use Symfony \Component \HttpFoundation \Request ;
1114use Symfony \Component \HttpFoundation \Response ;
1215
13- class DeviceController extends Controller
16+ class DeviceController
1417{
18+ private $ entityManager ;
19+
20+ private $ logger ;
21+
22+ private $ sessionStore ;
23+
24+ private $ deviceFingerprintManager ;
25+
26+ public function __construct (
27+ EntityManager $ entityManager ,
28+ LoggerInterface $ logger ,
29+ SessionStore $ sessionStore ,
30+ DeviceFingerprintManager $ deviceFingerprintManager
31+ ) {
32+ $ this ->entityManager = $ entityManager ;
33+ $ this ->logger = $ logger ;
34+ $ this ->sessionStore = $ sessionStore ;
35+ $ this ->deviceFingerprintManager = $ deviceFingerprintManager ;
36+ }
37+
1538 public function fingerprintAction (Request $ request ): Response
1639 {
17- $ em = $ this ->getDoctrine ()->getManager ();
18-
19- $ session = $ this ->get ('alpha.visitor_tracking.storage.session ' )->getSession ();
40+ $ session = $ this ->sessionStore ->getSession ();
2041 $ device = null ;
2142
2243 if ($ session instanceof Session) {
@@ -30,12 +51,12 @@ public function fingerprintAction(Request $request): Response
3051 $ device ->setFingerprint ($ request ->getContent ());
3152 $ device ->setSession ($ session );
3253
33- $ this ->get ( ' alpha.visitor_tracking.manager.device_fingerprint ' ) ->generateHashes ($ device );
54+ $ this ->deviceFingerprintManager ->generateHashes ($ device );
3455
35- $ em ->persist ($ device );
36- $ em ->flush ($ device );
56+ $ this -> entityManager ->persist ($ device );
57+ $ this -> entityManager ->flush ($ device );
3758
38- $ this ->get ( ' logger ' ) ->debug (sprintf ('A new device fingerprint was added with the id %d. ' , $ device ->getId ()));
59+ $ this ->logger ->debug (\ sprintf ('A new device fingerprint was added with the id %d. ' , $ device ->getId ()));
3960
4061 return new Response ('' , 201 );
4162 }
0 commit comments