| 1 |
<?php |
| 2 |
|
| 3 |
namespace PostHog; |
| 4 |
|
| 5 |
abstract class Consumer |
| 6 |
{ |
| 7 |
protected $type = "Consumer"; |
| 8 |
|
| 9 |
protected $options; |
| 10 |
protected $apiKey; |
| 11 |
|
| 12 |
/** |
| 13 |
* Store our apiKey and options as part of this consumer |
| 14 |
* @param string $apiKey |
| 15 |
* @param array $options |
| 16 |
*/ |
| 17 |
public function __construct($apiKey, $options = array()) |
| 18 |
{ |
| 19 |
$this->apiKey = $apiKey; |
| 20 |
$this->options = $options; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Captures a user action |
| 25 |
* |
| 26 |
* @param array $message |
| 27 |
* @return boolean whether the capture call succeeded |
| 28 |
*/ |
| 29 |
abstract public function capture(array $message); |
| 30 |
|
| 31 |
/** |
| 32 |
* Tags properties about the user. |
| 33 |
* |
| 34 |
* @param array $message |
| 35 |
* @return boolean whether the identify call succeeded |
| 36 |
*/ |
| 37 |
abstract public function identify(array $message); |
| 38 |
|
| 39 |
/** |
| 40 |
* Aliases from one user id to another |
| 41 |
* |
| 42 |
* @param array $message |
| 43 |
* @return boolean whether the alias call succeeded |
| 44 |
*/ |
| 45 |
abstract public function alias(array $message); |
| 46 |
|
| 47 |
/** |
| 48 |
* Check whether debug mode is enabled |
| 49 |
* @return boolean |
| 50 |
*/ |
| 51 |
protected function debug() |
| 52 |
{ |
| 53 |
return isset($this->options["debug"]) ? $this->options["debug"] : false; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Check whether we should connect to the API using SSL. This is enabled by |
| 58 |
* default with connections which make batching requests. For connections |
| 59 |
* which can save on round-trip times, you may disable it. |
| 60 |
* @return boolean |
| 61 |
*/ |
| 62 |
protected function ssl() |
| 63 |
{ |
| 64 |
return isset($this->options["ssl"]) ? $this->options["ssl"] : true; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* On an error, try and call the error handler, if debugging output to |
| 69 |
* error_log as well. |
| 70 |
* @param string $code |
| 71 |
* @param string $msg |
| 72 |
*/ |
| 73 |
protected function handleError($code, $msg) |
| 74 |
{ |
| 75 |
if (isset($this->options['error_handler'])) { |
| 76 |
$handler = $this->options['error_handler']; |
| 77 |
$handler($code, $msg); |
| 78 |
} |
| 79 |
|
| 80 |
if ($this->debug()) { |
| 81 |
error_log("[PostHog][" . $this->type . "] " . $msg); |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|