Adapters are custom service programs that facilitates the integration with external systems for all outbound requests.
hhere is an example of an SMS adapter that will help in sending SMSs
Within the service-specific folder, you'll create an interface file that serves as the communication link between the application and the external service.
The interface file should be named following the pattern
The framework already has an inbuilt engine (called KGateway) responsible for handling SMS and email requests. It uses the adapter system to send SMS or emails by routing through these custom interfaces.
KGateway will look for the configured service (like tucksee-sms) in the registry and then connect to the corresponding adapter.
Inside your tucksee-sms folder, you will create a PHP class that implements the interface. This class should follow the convention of naming it with the service name and adding the suffix -provider. For example, TuckseeSmsProvider.php.
Class Documentation: Ensure your class includes detailed documentation that outlines:
Your class will contain the following two methods that KGateway will automatically invoke:
sendSms: Responsible for sending a single SMS.
sendBulkSms: Handles sending bulk SMS messages.
sendSms Method:
This method will accept an object, likely an SMS object, which will contain at least two properties:
MSISDN (Mobile Station International Subscriber Directory Number) - The phone number, formatted as
You may need to manipulate the number, based on the API requirements of the service you are connecting to (e.g., removing hyphens or leaving them intact).
The method will then connect to the external service using the appropriate connection method, whether it's through an HTTP request or an FTP upload, depending on the service.
sendBulkSms Method:
This method works similarly to sendSms, but instead of one phone number, it will receive:
A message (string).
An array of numbers (the same format as in sendSms).
You may need to loop through the array or format the numbers as required by the external service.
The key point is that adapters are custom and require manual integration. You need to examine the API documentation of the service you're connecting to and handle the specific logic for sending SMS or email messages as per their specifications.
By following these steps, youâll be able to integrate external services like SMS or email into your framework seamlessly while keeping things flexible and modular.
/**
* Tucksee SMS interface
*
* @owner
* @api reference api url
*/
class TuckseeProvider{
/**
* send an sms using tucksee gateway
*
* @param object $sms
*
* @return array success: => 1/0 , msg => message
*/
final public function sendSms($sms){
// call your API for sending sms: curl -> senSms.call($sms->msisdn, $sms->content);
return array('success' => 1, 'msg' => 'sent');
}
/**
* send an bulk sms using tucksee gateway
*
* @param string $message
* @param array $numbers - array(mobile => reference_id)
*
* @return array success: => 1/0 , msg => message
*/
final public function sendBulkSms($message, $numbers){
// call your API for sending sms: curl -> senBulkSms.call($message, implode(',',$numbers);
return array('success' => 1, 'msg' => 'sent');
}
}
Your download is here.