2
2
3
3
declare (strict_types=1 );
4
4
5
- namespace App ;
5
+ namespace Evolv ;
6
6
7
- use App \EvolvContext ;
8
- use App \EvolvStore ;
9
- use App \Beacon ;
10
-
11
- use function App \Utils \waitFor ;
12
- use function App \Utils \emit ;
7
+ use function Evolv \Utils \waitFor ;
8
+ use function Evolv \Utils \emit ;
9
+ use Evolv \HttpClient ;
13
10
14
11
require __DIR__ . '/../vendor/autoload.php ' ;
15
- require_once __DIR__ . '/EvolvStore.php ' ;
16
- require_once __DIR__ . '/Beacon.php ' ;
17
- require_once __DIR__ . '/Utils/waitForIt.php ' ;
18
12
19
13
class EvolvClient
20
14
{
@@ -30,7 +24,13 @@ class EvolvClient
30
24
private Beacon $ contextBeacon ;
31
25
private Beacon $ eventBeacon ;
32
26
33
- public function __construct (string $ environment , string $ endpoint = 'https://participants.evolv.ai/ ' , bool $ autoconfirm = true )
27
+ /**
28
+ * @param string $environment
29
+ * @param string $endpoint
30
+ * @param bool $autoconfirm
31
+ * @return object
32
+ */
33
+ public function __construct (string $ environment , string $ endpoint = 'https://participants.evolv.ai/ ' , bool $ autoconfirm = true , $ llist = false )
34
34
{
35
35
$ this ->context = new EvolvContext ();
36
36
$ this ->store = new EvolvStore ($ environment , $ endpoint );
@@ -39,29 +39,33 @@ public function __construct(string $environment, string $endpoint = 'https://par
39
39
$ this ->eventBeacon = new Beacon ($ endpoint . 'v1/ ' . $ environment . '/events ' , $ this ->context );
40
40
41
41
$ this ->autoconfirm = $ autoconfirm ;
42
+
42
43
}
43
44
44
45
/**
45
46
* Initializes the client with required context information.
46
47
*
47
- * @param {String} uid A globally unique identifier for the current participant.
48
- * @param {String} sid A globally unique session identifier for the current participant .
49
- * @param {Object} remoteContext A map of data used for evaluating context predicates and analytics .
50
- * @param {Object} localContext A map of data used only for evaluating context predicates.
48
+ * @param string $ uid A globally unique identifier for the current participant.
49
+ * @param object $remoteContext A map of data used for evaluating context predicates and analytics .
50
+ * @param object $localContext A map of data used only for evaluating context predicates.
51
+ * @return array
51
52
*/
52
53
53
- public function initialize (string $ uid , array $ remoteContext = [], array $ localContext = [])
54
+ public function initialize (string $ uid , array $ remoteContext = [], array $ localContext = [], $ httpClient = null )
54
55
{
56
+
55
57
if ($ this ->initialized ) {
56
58
throw new \Exception ('Evolv: Client is already initialized ' );
59
+ exit ('Evolv: Client is already initialized ' );
57
60
}
58
61
59
62
if (!$ uid ) {
60
63
throw new \Exception ('Evolv: "uid" must be specified ' );
64
+ exit ('Evolv: "uid" must be specified ' );
61
65
}
62
66
63
67
$ this ->context ->initialize ($ uid , $ remoteContext , $ localContext );
64
- $ this ->store ->initialize ($ this ->context );
68
+ $ this ->store ->initialize ($ this ->context , $ httpClient );
65
69
66
70
if ($ this ->autoconfirm ) {
67
71
$ this ->confirm ();
@@ -113,10 +117,10 @@ public function initialize(string $uid, array $remoteContext = [], array $localC
113
117
* * "contaminated" - Called when the consumer is contaminated (topic)
114
118
* * "event.emitted" - Called when an event is emitted through the beacon (topic, type, score)
115
119
*
116
- * @param string topic The event topic on which the listener should be invoked.
117
- * @param callable listener The listener to be invoked for the specified topic.
118
- * @method
119
- * @see {@link EvolvClient#once} for listeners that should only be invoked once.
120
+ * @param string $ topic The event topic on which the listener should be invoked.
121
+ * @param callable $ listener The listener to be invoked for the specified topic.
122
+ * @function
123
+ * @see EvolvClient for listeners that should only be invoked once.
120
124
*/
121
125
public function on (string $ topic , callable $ listener )
122
126
{
@@ -126,9 +130,9 @@ public function on(string $topic, callable $listener)
126
130
/**
127
131
* Send an event to the events endpoint.
128
132
*
129
- * @param {String} type The type associated with the event.
130
- * @param metadata {Object} Any metadata to attach to the event.
131
- * @param flush {Boolean} If true, the event will be sent immediately.
133
+ * @param string $ type The type associated with the event.
134
+ * @param object $ metadata Any metadata to attach to the event.
135
+ * @param boolean $flush If true, the event will be sent immediately.
132
136
*/
133
137
public function emit (string $ type , $ metadata , bool $ flush = false )
134
138
{
@@ -143,10 +147,10 @@ public function emit(string $type, $metadata, bool $flush = false)
143
147
/**
144
148
* Check all active keys that start with the specified prefix.
145
149
*
146
- * @param {String} prefix The prefix of the keys to check.
150
+ * @param string $ prefix The prefix of the keys to check.
147
151
* @returns {SubscribablePromise.<Object|Error>} A SubscribablePromise that resolves to object
148
152
* describing the state of active keys.
149
- * @method
153
+ * @function
150
154
*/
151
155
public function getActiveKeys (string $ prefix = '' , callable $ listener = null )
152
156
{
@@ -156,9 +160,9 @@ public function getActiveKeys(string $prefix = '', callable $listener = null)
156
160
/**
157
161
* Get the value of a specified key.
158
162
*
159
- * @param {String} key The key of the value to retrieve.
163
+ * @param string $ key The key of the value to retrieve.
160
164
* @returns @mixed A value of the specified key.
161
- * @method
165
+ * @function
162
166
*/
163
167
public function get (string $ key = '' , callable $ listener = null )
164
168
{
@@ -211,11 +215,11 @@ public function confirm()
211
215
$ this ->context ->update (['experiments ' => ['confirmations ' => $ newConfirmations ]]);
212
216
213
217
foreach ($ confirmableAllocations as $ alloc ) {
214
- $ this ->eventBeacon ->emit ('confirmation ' , array_merge ( [
218
+ $ this ->eventBeacon ->emit ('confirmation ' , [
215
219
'uid ' => $ alloc ['uid ' ],
216
220
'eid ' => $ alloc ['eid ' ],
217
221
'cid ' => $ alloc ['cid ' ]
218
- ], $ this -> context -> remoteContext ) );
222
+ ]);
219
223
};
220
224
221
225
$ this ->eventBeacon ->flush ();
@@ -227,9 +231,9 @@ public function confirm()
227
231
* Marks a consumer as unsuccessfully retrieving and / or applying requested values, making them ineligible for
228
232
* inclusion in optimization statistics.
229
233
*
230
- * @param details {Object} Optional. Information on the reason for contamination. If provided, the object should
234
+ * @param object $details Optional. Information on the reason for contamination. If provided, the object should
231
235
* contain a reason. Optionally, a 'details' value should be included for extra debugging info
232
- * @param { boolean} allExperiments If true, the user will be excluded from all optimizations, including optimization
236
+ * @param boolean $ allExperiments If true, the user will be excluded from all optimizations, including optimization
233
237
* not applicable to this page
234
238
*/
235
239
public function contaminate ($ details , bool $ allExperiments = false )
@@ -267,12 +271,12 @@ public function contaminate($details, bool $allExperiments = false)
267
271
$ this ->context ->update (['experiments ' => ['contaminations ' => $ newContaminations ]]);
268
272
269
273
foreach ($ contaminatableAllocations as $ alloc ) {
270
- $ this ->eventBeacon ->emit ('contamination ' , array_merge ( [
274
+ $ this ->eventBeacon ->emit ('contamination ' , [
271
275
'uid ' => $ alloc ['uid ' ],
272
276
'eid ' => $ alloc ['eid ' ],
273
277
'cid ' => $ alloc ['cid ' ],
274
278
'contaminationReason ' => $ details
275
- ], $ this -> context -> remoteContext ) );
279
+ ]);
276
280
};
277
281
278
282
$ this ->eventBeacon ->flush ();
0 commit comments