protected __construct ( DataSift_User $user, mixed $definition, DataSift_IStreamConsumerEventHandler $eventHandler ) | ||
$user | DataSift_User | The user this consumer will run as. |
$definition | mixed | CSDL string, a Definition object, or an array of hashes. |
$eventHandler | DataSift_IStreamConsumerEventHandler | The object that will receive events. |
protected function __construct($user, $definition, $eventHandler)
{
if (!$user instanceof DataSift_User) {
throw new DataSift_Exception_InvalidData('Please supply a valid DataSift_User object when creating a DataSift_StreamConsumer object.');
}
if (is_array($definition) && count($definition) > 0) {
// Yes, we're multi
$this->_is_multi = true;
// Get the hashes
foreach ($definition as $d) {
if ($d instanceof DataSift_Definition) {
$this->_hashes[] = $d->getHash();
} else {
$this->_hashes[] = $d;
}
}
} elseif (is_string($definition)) {
// Convert the CSDL into a Definition object
$this->_definition = $user->createDefinition($definition);
} elseif ($definition instanceof DataSift_Definition) {
// Already a Definition object
$this->_definition = $definition;
} else {
throw new DataSift_Exception_InvalidData('The definition must be a CSDL string, a DataSift_Definition object, or an array of stream hashes.');
}
// Set the user
$this->_user = $user;
// Validate and set the event handler
if (!$eventHandler instanceof DataSift_IStreamConsumerEventHandler) {
throw new DataSift_Exception_InvalidData('Your event handler object must implement the DataSift_IStreamConsumerEventHandler interface.');
}
$this->_eventHandler = $eventHandler;
// Ask for the definition hash - this will compile the definition if
// necessary
if (!$this->_is_multi) {
$this->_definition->getHash();
}
}
/** * Constructor. * * @param DataSift_User $user The authenticated user * @param mixed $definition CSDL string, Definition object, or array of hashes * @param mixed $eventHandler An object that implements IStreamConsumerEventHandler * * @throws DataSift_Exception_InvalidData * @throws DataSift_Exceotion_CompileFailed * @throws DataSift_Exception_APIError * @see DataSift_StreamConsumer::__construct */ public function __construct($user, $definition, $eventHandler) { parent::__construct($user, $definition, $eventHandler); }