PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / wp-media / wp-mixpanel / src / Classes / ConsumerStrategies / AbstractConsumer.php

AbstractConsumer.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at vendor/wp-media/wp-mixpanel/src/Classes/ConsumerStrategies/AbstractConsumer.php

64 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Provides some base methods for use by a Consumer implementation
5 */
6 abstract class Imagify_WPMedia_ConsumerStrategies_AbstractConsumer extends Imagify_WPMedia_Base_MixpanelBase {
7
8 /**
9 * Creates a new AbstractConsumer
10 * @param array $options
11 */
12 function __construct($options = array()) {
13
14 parent::__construct($options);
15
16 if ($this->_debug()) {
17 $this->_log("Instantiated new Consumer");
18 }
19
20 }
21
22 /**
23 * Encode an array to be persisted
24 * @param array $params
25 * @return string
26 */
27 protected function _encode($params) {
28 return base64_encode(json_encode($params));
29 }
30
31 /**
32 * Handles errors that occur in a consumer
33 * @param $code
34 * @param $msg
35 */
36 protected function _handleError($code, $msg) {
37 if (isset($this->_options['error_callback'])) {
38 $handler = $this->_options['error_callback'];
39 call_user_func($handler, $code, $msg);
40 }
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 /**
51 * Number of requests/batches that will be processed in parallel.
52 * @return int
53 */
54 public function getNumThreads() {
55 return 1;
56 }
57
58 /**
59 * Persist a batch of messages in whatever way the implementer sees fit
60 * @param array $batch an array of messages to consume
61 * @return boolean success or fail
62 */
63 abstract function persist($batch);
64 }