本文整理汇总了PHP中DataProvider::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP DataProvider::factory方法的具体用法?PHP DataProvider::factory怎么用?PHP DataProvider::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataProvider
的用法示例。
在下文中一共展示了DataProvider::factory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_gather
/**
* Callback for 'gather' response on call to Twilio
*/
public function action_gather()
{
if ($this->request->method() != 'POST') {
// Only POST is allowed
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::POST))->allowed(Http_Request::POST);
}
$provider = DataProvider::factory('twilio');
// Authenticate the request
$options = $provider->options();
if ($this->request->post('AccountSid') !== $options['account_sid']) {
// Could not authenticate the request?
throw HTTP_Exception::factory(403, 'Incorrect or missing AccountSid');
}
// Remove Non-Numeric characters because that's what the DB has
$to = preg_replace("/[^0-9,.]/", "", $this->request->post('To'));
$from = preg_replace("/[^0-9,.]/", "", $this->request->post('From'));
$message_sid = $this->request->post('CallSid');
$digits = $this->request->post('Digits');
if ($digits == 1) {
$message_text = 'IVR: Okay';
} else {
if ($digits == 2) {
$message_text = 'IVR: Not Okay';
} else {
// HALT
Kohana::$log->add(Log::ERROR, __("':digits' is not a valid IVR response", array(":digits" => $digits)));
return;
}
}
$provider->receive(Message_Type::IVR, $from, $message_text, $to, NULL, $message_sid);
}
示例2: action_index
public function action_index()
{
// Set up custom error view
Kohana_Exception::$error_view = 'error/data-provider';
if ($this->request->method() != 'GET') {
// Only GET is allowed as FrontlineSms does only GET request
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::GET))->allowed(Http_Request::GET);
}
$provider = DataProvider::factory('frontlinesms');
// Authenticate the request
$options = $provider->options();
if (!isset($options['key']) or empty($options['key'])) {
throw HTTP_Exception::factory(403, 'Key value has not been configured');
}
if (!$this->request->query('key') or $this->request->query('key') != $options['key']) {
throw HTTP_Exception::factory(403, 'Incorrect or missing key');
}
if (!$this->request->query('m')) {
throw HTTP_Exception::factory(403, 'Missing message');
}
// Remove Non-Numeric characters because that's what the DB has
$from = preg_replace('/\\D+/', "", $this->request->post('from'));
$message_text = $this->request->query('m');
// If receiving an SMS Message
if ($from and $message_text) {
$provider->receive(Message_Type::SMS, $from, $message_text, $to);
}
$json = array('payload' => array('success' => TRUE, 'error' => NULL));
// Set the correct content-type header
$this->response->headers('Content-Type', 'application/json');
$this->response->body(json_encode($json));
}
示例3: action_reply
/**
* Handle incoming SMS from Twilio
*/
public function action_reply()
{
//Check if data provider is available
$providers_available = Kohana::$config->load('features.data-providers');
if (!$providers_available['twilio']) {
throw HTTP_Exception::factory(403, 'The Twilio data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.');
}
if ($this->request->method() != 'POST') {
// Only POST is allowed
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::POST))->allowed(Http_Request::POST);
}
$provider = DataProvider::factory('twilio');
// Authenticate the request
$options = $provider->options();
if ($this->request->post('AccountSid') !== $options['account_sid']) {
throw HTTP_Exception::factory(403, 'Incorrect or missing AccountSid');
}
// Remove Non-Numeric characters because that's what the DB has
$to = preg_replace("/[^0-9,.]/", "", $this->request->post('To'));
$from = preg_replace("/[^0-9,.]/", "", $this->request->post('From'));
$message_text = $this->request->post('Body');
$message_sid = $this->request->post('MessageSid');
// @todo use other info from twillio, ie: location, media
$provider->receive(Message_Type::SMS, $from, $message_text, $to, NULL, $message_sid);
// If we have an auto response configured, return the response messages
if (!empty($options['sms_auto_response'])) {
$body = View::factory('twillio/sms_response')->set('response', $options['sms_auto_response'])->render();
// Set the correct content-type header
$this->response->headers('Content-Type', 'text/xml');
$this->response->body($body);
}
}
示例4: action_index
public function action_index()
{
// Set up custom error view
Kohana_Exception::$error_view = 'error/data-provider';
//Check if data provider is available
$providers_available = Kohana::$config->load('features.data-providers');
if (!$providers_available['smssync']) {
throw HTTP_Exception::factory(403, 'The SMS Sync data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.');
}
$methods_with_http_request = [Http_Request::POST, Http_Request::GET];
if (!in_array($this->request->method(), $methods_with_http_request)) {
// Only POST or GET is allowed
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => implode(',', $methods_with_http_request)))->allowed($methods_with_http_request);
}
$this->_provider = DataProvider::factory('smssync');
$this->options = $this->_provider->options();
// Ensure we're always returning a payload..
// This will be overwritten later if incoming or task methods are run
$this->_json['payload'] = ['success' => TRUE, 'error' => NULL];
// Process incoming messages from SMSSync only if the request is POST
if ($this->request->method() == 'POST') {
$this->_incoming();
}
// Attempt Task if request is GET and task type is 'send'
if ($this->request->method() == 'GET' and $this->request->query('task') == 'send') {
$this->_task();
}
// Set the response
$this->_set_response();
}
示例5: execute_incoming
protected function execute_incoming(InputInterface $input, OutputInterface $output)
{
$providers = $this->get_providers($input, $output);
$limit = $input->getOption('limit');
$totals = [];
foreach ($providers as $id => $provider) {
$totals[] = ['Provider' => $provider->name, 'Total' => \DataProvider::factory($id)->fetch($limit)];
}
return $totals;
}
示例6: action_index
public function action_index()
{
// Set up custom error view
Kohana_Exception::$error_view = 'error/data-provider';
$methods_with_http_request = [Http_Request::POST, Http_Request::GET];
if (!in_array($this->request->method(), $methods_with_http_request)) {
// Only POST or GET is allowed
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => implode(',', $methods_with_http_request)))->allowed($methods_with_http_request);
}
$this->_provider = DataProvider::factory('smssync');
$this->options = $this->_provider->options();
// Process incoming messages from SMSSync only if the request is POST
if ($this->request->method() == 'POST') {
$this->_incoming();
}
// Attempt Task if request is GET and task type is 'send'
if ($this->request->method() == 'GET' and $this->request->query('task') == 'send') {
$this->_task();
}
// Set the response
$this->_set_response();
}
示例7: process_pending_messages
/**
* Process pending messages for provider
*
* For services where we can push messages (rather than being polled like SMS Sync):
* this should grab pending messages and pass them to send()
*
* @param boolean $limit maximum number of messages to send at a time
*/
public static function process_pending_messages($limit = 20, $provider = FALSE)
{
$message_repo = service('repository.message');
$contact_repo = service('repository.contact');
$providers = array();
$count = 0;
// Grab latest messages
$pings = $message_repo->getPendingMessages(Message_Status::PENDING, $provider, $limit);
foreach ($pings as $message) {
$provider = DataProvider::factory($message->data_provider, $message->type);
// Load contact
$contact = $contact_repo->get($message->contact_id);
// Send message and get new status/tracking id
list($new_status, $tracking_id) = $provider->send($contact->contact, $message->message, $message->title);
// Update message details
$message->status = $new_status;
$message->data_provider = $provider->provider_name();
if ($tracking_id) {
$message->data_provider_message_id = $tracking_id;
}
// @todo handle errors
$message_repo->update($message);
$count++;
}
return $count;
}
示例8: action_reply
/**
* Handle SMS from Nexmo
*/
public function action_reply()
{
include_once Kohana::find_file('vendor', 'nexmo/NexmoMessage');
// Pong Sender
$ip_address = $_SERVER["REMOTE_ADDR"];
$continue = FALSE;
foreach ($this->subnets as $subnet) {
if ($this->_ip_in_range($ip_address, $subnet)) {
throw HTTP_Exception::factory(403, 'IP Address not in allowed range');
break;
}
}
$provider = DataProvider::factory('nexmo');
$options = $provider->options();
if (!isset($options['api_key'])) {
throw HTTP_Exception::factory(403, 'Missing API key');
}
if (!isset($options['api_secret'])) {
throw HTTP_Exception::factory(403, 'Missing API secret');
}
$sms = new NexmoMessage($options['api_key'], $options['api_secret']);
if (!$sms->inboundText()) {
throw HTTP_Exception::factory(400, "Invalid message");
}
// Remove Non-Numeric characters because that's what the DB has
$to = preg_replace("/[^0-9,.]/", "", $sms->to);
$from = preg_replace("/[^0-9,.]/", "", $sms->from);
$provider->receive(Message_Type::SMS, $from, $sms->text, $to, NULL, $sms->message_id);
}
示例9: action_reply
/**
* Handle SMS from Nexmo
*/
public function action_reply()
{
include_once Kohana::find_file('vendor', 'nexmo/NexmoMessage');
//Check if data provider is available
$providers_available = Kohana::$config->load('features.data-providers');
if (!$providers_available['nexmo']) {
throw HTTP_Exception::factory(403, 'The Nexmo data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.');
}
// Pong Sender
$ip_address = $_SERVER["REMOTE_ADDR"];
$continue = FALSE;
foreach ($this->subnets as $subnet) {
if ($this->_ip_in_range($ip_address, $subnet)) {
throw HTTP_Exception::factory(403, 'IP Address not in allowed range');
break;
}
}
$provider = DataProvider::factory('nexmo');
$options = $provider->options();
if (!isset($options['api_key'])) {
throw HTTP_Exception::factory(403, 'Missing API key');
}
if (!isset($options['api_secret'])) {
throw HTTP_Exception::factory(403, 'Missing API secret');
}
$sms = new NexmoMessage($options['api_key'], $options['api_secret']);
if (!$sms->inboundText()) {
throw HTTP_Exception::factory(400, "Invalid message");
}
// Remove Non-Numeric characters because that's what the DB has
$to = preg_replace("/[^0-9,.]/", "", $sms->to);
$from = preg_replace("/[^0-9,.]/", "", $sms->from);
$provider->receive(Message_Type::SMS, $from, $sms->text, $to, NULL, $sms->message_id);
}