4
4
5
5
use App \Http \HtmlResponse ;
6
6
use App \Model \UrlShortener \Shortlink ;
7
+ use App \Model \UrlShortener \ShortlinkTracking ;
7
8
use App \Service \UrlShortener \ShortlinkPasswordService ;
8
9
use App \Service \UrlShortener \ShortlinkService ;
10
+ use App \Service \UrlShortener \ShortlinkTrackingService ;
9
11
use Laminas \Diactoros \Response \RedirectResponse ;
10
12
use League \Plates \Engine ;
11
13
use Psr \Http \Message \ResponseInterface ;
@@ -17,7 +19,8 @@ class LinkController
17
19
public function __construct (
18
20
private readonly Engine $ template ,
19
21
private readonly ShortlinkService $ shortlinkService ,
20
- private readonly ShortlinkPasswordService $ passwordService
22
+ private readonly ShortlinkPasswordService $ passwordService ,
23
+ private readonly ShortlinkTrackingService $ shortlinkTrackingService
21
24
)
22
25
{
23
26
}
@@ -38,6 +41,7 @@ public function load(ServerRequestInterface $request, array $args): ResponseInte
38
41
39
42
if (empty ($ shortlink ->getDestination ()))
40
43
{
44
+ MESSAGES ->add ('danger ' , 'url-shortener-link-not-found ' );
41
45
return new HtmlResponse ($ this ->template ->render ('urlShortener/linkInformation ' ));
42
46
}
43
47
@@ -58,6 +62,16 @@ public function load(ServerRequestInterface $request, array $args): ResponseInte
58
62
return new HtmlResponse ($ this ->template ->render ('urlShortener/linkInformation ' ));
59
63
}
60
64
65
+ if ($ shortlink ->isTracking ())
66
+ {
67
+ $ tracking = new ShortlinkTracking ();
68
+ $ tracking ->setLink ($ shortlink ->getId ());
69
+ $ tracking ->setUserIp ($ _SERVER ['REMOTE_ADDR ' ]);
70
+ $ tracking ->setUseragent ($ _SERVER ['HTTP_USER_AGENT ' ]);
71
+ $ tracking ->setAccessed (new \DateTime ());
72
+ $ this ->shortlinkTrackingService ->track ($ tracking );
73
+ }
74
+
61
75
return new RedirectResponse ($ shortlink ->getDestination ());
62
76
63
77
}
0 commit comments