| 1 |
<?php |
| 2 |
|
| 3 |
namespace ElementorDeps; |
| 4 |
|
| 5 |
require_once \dirname(__FILE__) . "/../Base/MixpanelBase.php"; |
| 6 |
/** |
| 7 |
* Provides some base methods for use by a Consumer implementation |
| 8 |
*/ |
| 9 |
abstract class ConsumerStrategies_AbstractConsumer extends Base_MixpanelBase |
| 10 |
{ |
| 11 |
/** |
| 12 |
* Creates a new AbstractConsumer |
| 13 |
* @param array $options |
| 14 |
*/ |
| 15 |
function __construct($options = array()) |
| 16 |
{ |
| 17 |
parent::__construct($options); |
| 18 |
if ($this->_debug()) { |
| 19 |
$this->_log("Instantiated new Consumer"); |
| 20 |
} |
| 21 |
} |
| 22 |
/** |
| 23 |
* Encode an array to be persisted |
| 24 |
* @param array $params |
| 25 |
* @return string |
| 26 |
*/ |
| 27 |
protected function _encode($params) |
| 28 |
{ |
| 29 |
return \base64_encode(\json_encode($params)); |
| 30 |
} |
| 31 |
/** |
| 32 |
* Handles errors that occur in a consumer |
| 33 |
* @param $code |
| 34 |
* @param $msg |
| 35 |
*/ |
| 36 |
protected function _handleError($code, $msg) |
| 37 |
{ |
| 38 |
if (isset($this->_options['error_callback'])) { |
| 39 |
$handler = $this->_options['error_callback']; |
| 40 |
\call_user_func($handler, $code, $msg); |
| 41 |
} |
| 42 |
if ($this->_debug()) { |
| 43 |
$arr = \debug_backtrace(); |
| 44 |
$class = \get_class($arr[0]['object']); |
| 45 |
$line = $arr[0]['line']; |
| 46 |
\error_log("[ {$class} - line {$line} ] : " . \print_r($msg, \true)); |
| 47 |
} |
| 48 |
} |
| 49 |
/** |
| 50 |
* Number of requests/batches that will be processed in parallel. |
| 51 |
* @return int |
| 52 |
*/ |
| 53 |
public function getNumThreads() |
| 54 |
{ |
| 55 |
return 1; |
| 56 |
} |
| 57 |
/** |
| 58 |
* Persist a batch of messages in whatever way the implementer sees fit |
| 59 |
* @param array $batch an array of messages to consume |
| 60 |
* @return boolean success or fail |
| 61 |
*/ |
| 62 |
abstract function persist($batch); |
| 63 |
} |
| 64 |
|