| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* This a Base class which all Mixpanel classes extend from to provide some very basic |
| 5 |
* debugging and logging functionality. It also serves to persist $_options across the library. |
| 6 |
* |
| 7 |
*/ |
| 8 |
class Imagify_WPMedia_Base_MixpanelBase { |
| 9 |
|
| 10 |
|
| 11 |
/** |
| 12 |
* Default options that can be overridden via the $options constructor arg |
| 13 |
* @var array |
| 14 |
*/ |
| 15 |
private $_defaults = array( |
| 16 |
"max_batch_size" => 50, // the max batch size Mixpanel will accept is 50, |
| 17 |
"max_queue_size" => 1000, // the max num of items to hold in memory before flushing |
| 18 |
"debug" => false, // enable/disable debug mode |
| 19 |
"consumer" => "curl", // which consumer to use |
| 20 |
"host" => "api.mixpanel.com", // the host name for api calls |
| 21 |
"events_endpoint" => "/track", // host relative endpoint for events |
| 22 |
"people_endpoint" => "/engage", // host relative endpoint for people updates |
| 23 |
"groups_endpoint" => "/groups", // host relative endpoint for groups updates |
| 24 |
"use_ssl" => true, // use ssl when available |
| 25 |
"error_callback" => null // callback to use on consumption failures |
| 26 |
); |
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* An array of options to be used by the Mixpanel library. |
| 31 |
* @var array |
| 32 |
*/ |
| 33 |
protected $_options = array(); |
| 34 |
|
| 35 |
|
| 36 |
/** |
| 37 |
* Construct a new MixpanelBase object and merge custom options with defaults |
| 38 |
* @param array $options |
| 39 |
*/ |
| 40 |
public function __construct($options = array()) { |
| 41 |
$options = array_merge($this->_defaults, $options); |
| 42 |
$this->_options = $options; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
/** |
| 47 |
* Log a message to PHP's error log |
| 48 |
* @param $msg |
| 49 |
*/ |
| 50 |
protected function _log($msg) { |
| 51 |
$arr = debug_backtrace(); |
| 52 |
$class = $arr[0]['class']; |
| 53 |
$line = $arr[0]['line']; |
| 54 |
error_log ( "[ $class - line $line ] : " . $msg ); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
/** |
| 59 |
* Returns true if in debug mode, false if in production mode |
| 60 |
* @return bool |
| 61 |
*/ |
| 62 |
protected function _debug() { |
| 63 |
return isset($this->_options["debug"]) && $this->_options["debug"] == true; |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|