Example #1
0
 /**
  * Singleton function used to manage this object.
  *
  * @param array $providerParams
  * @param bool $force
  *
  * @return object
  */
 public static function &singleton($providerParams = array(), $force = FALSE)
 {
     $mailingID = CRM_Utils_Array::value('mailing_id', $providerParams);
     $providerID = CRM_Utils_Array::value('provider_id', $providerParams);
     $providerName = CRM_Utils_Array::value('provider', $providerParams);
     if (!$providerID && $mailingID) {
         $providerID = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingID, 'sms_provider_id', 'id');
         $providerParams['provider_id'] = $providerID;
     }
     if ($providerID) {
         $providerName = CRM_SMS_BAO_Provider::getProviderInfo($providerID, 'name');
     }
     if (!$providerName) {
         CRM_Core_Error::fatal('Provider not known or not provided.');
     }
     $providerName = CRM_Utils_Type::escape($providerName, 'String');
     $cacheKey = "{$providerName}_" . (int) $providerID . "_" . (int) $mailingID;
     if (!isset(self::$_singleton[$cacheKey]) || $force) {
         $ext = CRM_Extension_System::singleton()->getMapper();
         if ($ext->isExtensionKey($providerName)) {
             $paymentClass = $ext->keyToClass($providerName);
             require_once "{$paymentClass}.php";
         } else {
             CRM_Core_Error::fatal("Could not locate extension for {$providerName}.");
         }
         self::$_singleton[$cacheKey] = $paymentClass::singleton($providerParams, $force);
     }
     return self::$_singleton[$cacheKey];
 }
 /**
  * singleton function used to manage this object
  *
  * @return object
  * @static
  *
  */
 static function &singleton($providerParams = array(), $force = FALSE)
 {
     $mailingID = CRM_Utils_Array::value('mailing_id', $providerParams);
     $providerID = CRM_Utils_Array::value('provider_id', $providerParams);
     // make clickatell default provider for now
     $providerName = CRM_Utils_Array::value('provider', $providerParams, 'clickatell');
     if (!$providerID && $mailingID) {
         $providerID = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingID, 'sms_provider_id', 'id');
         $providerParams['provider_id'] = $providerID;
     }
     if ($providerID) {
         $providerName = CRM_SMS_BAO_Provider::getProviderInfo($providerID, 'name');
     }
     if (!$providerName) {
         CRM_Core_Error::fatal('Provider not known or not provided.');
     }
     $providerName = CRM_Utils_Type::escape($providerName, 'String');
     $providerName = ucfirst($providerName);
     $cacheKey = "{$providerName}_" . (int) $providerID . "_" . (int) $mailingID;
     if (!isset(self::$_singleton[$cacheKey]) || $force) {
         self::$_singleton[$cacheKey] = eval('return ' . "CRM_SMS_Provider_{$providerName}" . '::singleton( $providerParams, $force );');
     }
     return self::$_singleton[$cacheKey];
 }
 /**
  * singleton function used to manage this object
  *
  * @return object
  * @static
  *
  */
 static function &singleton($providerParams = array(), $force = FALSE)
 {
     $providerID = CRM_Utils_Array::value('provider_id', $providerParams);
     $skipAuth = $providerID ? FALSE : TRUE;
     $cacheKey = (int) $providerID;
     if (!isset(self::$_singleton[$cacheKey]) || $force) {
         $provider = array();
         if ($providerID) {
             $provider = CRM_SMS_BAO_Provider::getProviderInfo($providerID);
         }
         self::$_singleton[$cacheKey] = new org_civicrm_sms_twilio($provider, $skipAuth);
     }
     return self::$_singleton[$cacheKey];
 }