3
3
namespace SplitIO \ThinSdk ;
4
4
5
5
use \SplitIO \ThinSdk \Utils \ImpressionListener ;
6
+ use \SplitIO \ThinSdk \Utils \InputValidator \InputValidator ;
7
+ use \SplitIO \ThinSdk \Utils \InputValidator \ValidationException ;
6
8
use \SplitIO \ThinSdk \Models \Impression ;
7
9
use \SplitIO \ThinSdk \Link \Consumer \Manager ;
8
10
use \SplitIO \ThinSdk \Link \Protocol \V1 \ImpressionListenerData ;
@@ -14,12 +16,14 @@ class Client implements ClientInterface
14
16
private /*Link\Consumer\Manager*/ $ lm ;
15
17
private /*LoggerInterface*/ $ logger ;
16
18
private /*?ImpressionListener*/ $ impressionListener ;
19
+ private /*InputValidator*/ $ inputValidator ;
17
20
18
21
public function __construct (Manager $ manager , LoggerInterface $ logger , ?ImpressionListener $ impressionListener )
19
22
{
20
23
$ this ->logger = $ logger ;
21
24
$ this ->lm = $ manager ;
22
25
$ this ->impressionListener = $ impressionListener ;
26
+ $ this ->inputValidator = new InputValidator ($ logger );
23
27
}
24
28
25
29
public function getTreatment (string $ key , ?string $ bucketingKey , string $ feature , ?array $ attributes ): string
@@ -51,6 +55,19 @@ public function getTreatments(string $key, ?string $bucketingKey, array $feature
51
55
}
52
56
}
53
57
58
+ public function track (string $ key , string $ trafficType , string $ eventType , ?float $ value , ?array $ properties ): bool
59
+ {
60
+ try {
61
+ $ properties = $ this ->inputValidator ->validProperties ($ properties );
62
+ return $ this ->lm ->track ($ key , $ trafficType , $ eventType , $ value , $ properties );
63
+ } catch (ValidationException $ exc ) {
64
+ $ this ->logger ->error ("error validating event properties: " . $ exc ->getMessage ());
65
+ } catch (\Exception $ exc ) {
66
+ $ this ->logger ->error ($ exc );
67
+ }
68
+ return false ;
69
+ }
70
+
54
71
private function handleListener (string $ key , ?string $ bucketingKey , string $ feature , ?array $ attributes , string $ treatment , ?ImpressionListenerData $ ilData )
55
72
{
56
73
if ($ this ->impressionListener == null || $ ilData == null ) {
0 commit comments