-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tacking to improve the library use
- Loading branch information
1 parent
1d99115
commit 72f5f70
Showing
18 changed files
with
1,787 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* This a Base class which all Mixpanel classes extend from to provide some very basic | ||
* debugging and logging functionality. It also serves to persist $_options across the library. | ||
* | ||
*/ | ||
class Base_MixpanelBase { | ||
|
||
|
||
/** | ||
* Default options that can be overridden via the $options constructor arg | ||
* @var array | ||
*/ | ||
private $_defaults = array( | ||
"max_batch_size" => 50, // the max batch size Mixpanel will accept is 50, | ||
"max_queue_size" => 1000, // the max num of items to hold in memory before flushing | ||
"debug" => false, // enable/disable debug mode | ||
"consumer" => "curl", // which consumer to use | ||
"host" => "api.mixpanel.com", // the host name for api calls | ||
"events_endpoint" => "/track", // host relative endpoint for events | ||
"people_endpoint" => "/engage", // host relative endpoint for people updates | ||
"groups_endpoint" => "/groups", // host relative endpoint for groups updates | ||
"use_ssl" => true, // use ssl when available | ||
"error_callback" => null // callback to use on consumption failures | ||
); | ||
|
||
|
||
/** | ||
* An array of options to be used by the Mixpanel library. | ||
* @var array | ||
*/ | ||
protected $_options = array(); | ||
|
||
|
||
/** | ||
* Construct a new MixpanelBase object and merge custom options with defaults | ||
* @param array $options | ||
*/ | ||
public function __construct($options = array()) { | ||
$options = array_merge($this->_defaults, $options); | ||
$this->_options = $options; | ||
} | ||
|
||
|
||
/** | ||
* Log a message to PHP's error log | ||
* @param $msg | ||
*/ | ||
protected function _log($msg) { | ||
$arr = debug_backtrace(); | ||
$class = $arr[0]['class']; | ||
$line = $arr[0]['line']; | ||
error_log ( "[ $class - line $line ] : " . $msg ); | ||
} | ||
|
||
|
||
/** | ||
* Returns true if in debug mode, false if in production mode | ||
* @return bool | ||
*/ | ||
protected function _debug() { | ||
return isset($this->_options["debug"]) && $this->_options["debug"] == true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
require_once(dirname(__FILE__) . "/../Base/MixpanelBase.php"); | ||
|
||
/** | ||
* Provides some base methods for use by a Consumer implementation | ||
*/ | ||
abstract class ConsumerStrategies_AbstractConsumer extends Base_MixpanelBase { | ||
|
||
/** | ||
* Creates a new AbstractConsumer | ||
* @param array $options | ||
*/ | ||
function __construct($options = array()) { | ||
|
||
parent::__construct($options); | ||
|
||
if ($this->_debug()) { | ||
$this->_log("Instantiated new Consumer"); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Encode an array to be persisted | ||
* @param array $params | ||
* @return string | ||
*/ | ||
protected function _encode($params) { | ||
return base64_encode(json_encode($params)); | ||
} | ||
|
||
/** | ||
* Handles errors that occur in a consumer | ||
* @param $code | ||
* @param $msg | ||
*/ | ||
protected function _handleError($code, $msg) { | ||
if (isset($this->_options['error_callback'])) { | ||
$handler = $this->_options['error_callback']; | ||
call_user_func($handler, $code, $msg); | ||
} | ||
|
||
if ($this->_debug()) { | ||
$arr = debug_backtrace(); | ||
$class = get_class($arr[0]['object']); | ||
$line = $arr[0]['line']; | ||
error_log ( "[ $class - line $line ] : " . print_r($msg, true) ); | ||
} | ||
} | ||
|
||
/** | ||
* Number of requests/batches that will be processed in parallel. | ||
* @return int | ||
*/ | ||
public function getNumThreads() { | ||
return 1; | ||
} | ||
|
||
/** | ||
* Persist a batch of messages in whatever way the implementer sees fit | ||
* @param array $batch an array of messages to consume | ||
* @return boolean success or fail | ||
*/ | ||
abstract function persist($batch); | ||
} |
Oops, something went wrong.