1 | <?php |
||
16 | class BatchRequestSubscriber implements SubscriberInterface |
||
17 | { |
||
18 | /** |
||
19 | * Segment.io Client |
||
20 | * |
||
21 | * @var Client |
||
22 | */ |
||
23 | private $client = null; |
||
24 | |||
25 | /** |
||
26 | * Webservice Description. |
||
27 | * |
||
28 | * @var DescriptionInterface |
||
29 | */ |
||
30 | private $description; |
||
31 | |||
32 | /** |
||
33 | * Queue of Operations |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | private $queue = []; |
||
38 | |||
39 | /** |
||
40 | * Determines the maximum size the queue is allowed to reach. New items pushed |
||
41 | * to the queue will be ignored if this size is reached and cannot be flushed. |
||
42 | * Defaults to 10000. |
||
43 | * |
||
44 | * @var integer |
||
45 | */ |
||
46 | private $maxQueueSize = 10000; |
||
47 | |||
48 | /** |
||
49 | * Determines how many operations are sent to Segment.io in a single request. |
||
50 | * Defaults to 100. |
||
51 | * |
||
52 | * @var integer |
||
53 | */ |
||
54 | private $batchSize = 100; |
||
55 | |||
56 | /** |
||
57 | * Constructor |
||
58 | * |
||
59 | * @param DescriptionInterface $description |
||
60 | * @param array $options An array of configuration options |
||
61 | */ |
||
62 | public function __construct(DescriptionInterface $description, array $options = []) |
||
73 | |||
74 | /** |
||
75 | * Destructor |
||
76 | * |
||
77 | * Flushes any queued Operations |
||
78 | */ |
||
79 | public function __destruct() |
||
84 | |||
85 | /** |
||
86 | * Returns the Subscribed Events |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | public function getEvents() |
||
97 | |||
98 | /** |
||
99 | * Event to add Segment.io Specific data to the Event Messages |
||
100 | * |
||
101 | * @param PreparedEvent $event The PreparedEvent |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function onPrepared(PreparedEvent $event) |
||
125 | |||
126 | /** |
||
127 | * Stops propagation of ProcessEvents when using Batching |
||
128 | * |
||
129 | * @param ProcessEvent $event The Process Event |
||
130 | * |
||
131 | * @return bool |
||
132 | */ |
||
133 | public function onProcess(ProcessEvent $event) |
||
146 | |||
147 | /** |
||
148 | * Adds User Actions to the Queue |
||
149 | * |
||
150 | * Will attempt to flush the queue if the size of the queue has reached |
||
151 | * the Max Queue Size |
||
152 | * |
||
153 | * @param array $operation Operation as an associative array |
||
154 | * |
||
155 | * @return boolean |
||
156 | */ |
||
157 | public function enqueue(array $operation) |
||
170 | |||
171 | /** |
||
172 | * Flushes the queue by batching Import operations |
||
173 | * |
||
174 | * @return boolean |
||
175 | */ |
||
176 | public function flush() |
||
189 | |||
190 | } |
||
191 |