4
4
/**
5
5
* @internal
6
6
*/
7
- class EventProcessor {
7
+ class EventProcessor
8
+ {
9
+ private $ _eventPublisher ;
10
+ private $ _queue ;
11
+ private $ _capacity ;
12
+ private $ _timeout ;
8
13
9
- private $ _eventPublisher ;
10
- private $ _queue ;
11
- private $ _capacity ;
12
- private $ _timeout ;
14
+ public function __construct ($ sdkKey , $ options = array ())
15
+ {
16
+ $ this ->_eventPublisher = $ this ->getEventPublisher ($ sdkKey , $ options );
13
17
14
- public function __construct ( $ sdkKey , $ options = array ()) {
15
- $ this ->_eventPublisher = $ this -> getEventPublisher ( $ sdkKey , $ options) ;
18
+ $ this -> _capacity = $ options [ ' capacity ' ];
19
+ $ this ->_timeout = $ options[ ' timeout ' ] ;
16
20
17
- $ this ->_capacity = $ options ['capacity ' ];
18
- $ this ->_timeout = $ options ['timeout ' ];
19
-
20
- $ this ->_queue = array ();
21
- }
22
-
23
- public function __destruct () {
24
- $ this ->flush ();
25
- }
21
+ $ this ->_queue = array ();
22
+ }
26
23
27
- public function sendEvent ($ event ) {
28
- return $ this ->enqueue ($ event );
29
- }
24
+ public function __destruct ()
25
+ {
26
+ $ this ->flush ();
27
+ }
30
28
31
- public function enqueue ($ event ) {
32
- if ( count ( $ this -> _queue ) > $ this -> _capacity ) {
33
- return false ;
29
+ public function sendEvent ($ event )
30
+ {
31
+ return $ this -> enqueue ( $ event ) ;
34
32
}
35
33
36
- array_push ($ this ->_queue , $ event );
34
+ public function enqueue ($ event )
35
+ {
36
+ if (count ($ this ->_queue ) > $ this ->_capacity ) {
37
+ return false ;
38
+ }
37
39
38
- return true ;
39
- }
40
+ array_push ($ this ->_queue , $ event );
41
+
42
+ return true ;
43
+ }
40
44
41
45
/**
42
46
* Publish events to LaunchDarkly
43
47
* @return bool Whether the events were successfully published
44
48
*/
45
- public function flush () {
46
- if (empty ($ this ->_queue )) {
47
- return null ;
48
- }
49
+ public function flush ()
50
+ {
51
+ if (empty ($ this ->_queue )) {
52
+ return null ;
53
+ }
49
54
50
- $ payload = json_encode ($ this ->_queue );
55
+ $ payload = json_encode ($ this ->_queue );
51
56
52
- return $ this ->_eventPublisher ->publish ($ payload );
57
+ return $ this ->_eventPublisher ->publish ($ payload );
53
58
}
54
59
55
60
/**
@@ -59,19 +64,19 @@ public function flush() {
59
64
*/
60
65
private function getEventPublisher ($ sdkKey , array $ options )
61
66
{
62
- if (isset ($ options ['event_publisher ' ]) && $ options ['event_publisher ' ] instanceof EventPublisher) {
63
- return $ options ['event_publisher ' ];
64
- }
65
-
66
- if (isset ($ options ['event_publisher_class ' ])) {
67
- $ eventPublisherClass = $ options ['event_publisher_class ' ];
68
- } else {
69
- $ eventPublisherClass = CurlEventPublisher::class;
70
- }
71
-
72
- if (!is_a ($ eventPublisherClass , EventPublisher::class, true )) {
73
- throw new \InvalidArgumentException ;
74
- }
75
- return new $ eventPublisherClass ($ sdkKey , $ options );
67
+ if (isset ($ options ['event_publisher ' ]) && $ options ['event_publisher ' ] instanceof EventPublisher) {
68
+ return $ options ['event_publisher ' ];
69
+ }
70
+
71
+ if (isset ($ options ['event_publisher_class ' ])) {
72
+ $ eventPublisherClass = $ options ['event_publisher_class ' ];
73
+ } else {
74
+ $ eventPublisherClass = CurlEventPublisher::class;
75
+ }
76
+
77
+ if (!is_a ($ eventPublisherClass , EventPublisher::class, true )) {
78
+ throw new \InvalidArgumentException ;
79
+ }
80
+ return new $ eventPublisherClass ($ sdkKey , $ options );
76
81
}
77
- }
82
+ }
0 commit comments