composer require avator/symfony-turbosms
app/AppKernel.php:
new AVATOR\TurbosmsBundle\AVATORTurbosmsBundle(),
config.yml:
avator_turbosms:
login: 'your_turbosms_login'
password: 'your_turbosms_password'
sender: 'YourSenderName'
debug: false
save_to_db: true
php bin/console doctrine:schema:update --dump-sql
Review SQL, then execute --force if needed.Send an SMS in a controller:
use AVATOR\TurbosmsBundle\Service\TurbosmsService;
class DefaultController extends Controller
{
public function sendSmsAction()
{
$turbosms = $this->get('avator_turbosms.turbosms');
$success = $turbosms->send("Hello via Turbosms!", "+380991234567");
return new Response($success ? 'SMS sent!' : 'Failed');
}
}
Service Injection Use dependency injection to access the service:
$turbosms = $this->container->get('avator_turbosms.turbosms');
Or via autowiring (Symfony 3.3+):
use AVATOR\TurbosmsBundle\Service\TurbosmsService;
public function __construct(TurbosmsService $turbosms) {
$this->turbosms = $turbosms;
}
Sending SMS Basic usage:
$this->turbosms->send("Message", "+380991234567");
With options (if extended):
$this->turbosms->send("Message", "+380991234567", ['priority' => 'high']);
Database Logging
If save_to_db: true, logs are stored in avator_turbosms_message table. Query logs via:
$logs = $this->getDoctrine()->getRepository('AVATORTurbosmsBundle:Message')->findAll();
Debug Mode
Set debug: true to prevent actual sends (useful for testing).
services:
app.turbosms_listener:
class: AppBundle\EventListener\TurbosmsListener
tags:
- { name: kernel.event_listener, event: avator.turbosms.post_send, method: onPostSend }
$recipients = ['+380991234567', '+380991234568'];
foreach ($recipients as $phone) {
$this->turbosms->send("Batch message", $phone);
}
libphonenumber):
use libphonenumber\PhoneNumberUtil;
$phoneUtil = PhoneNumberUtil::getInstance();
$phone = $phoneUtil->parse($phoneNumber);
if (!$phoneUtil->isValidNumber($phone)) {
throw new \InvalidArgumentException("Invalid phone number");
}
Deprecated Symfony Version
catch (\SoapFault $fault) {
// Handle SOAP errors (e.g., login/password mismatch)
}
Database Schema
doctrine:schema:update step is critical. Skipping it will cause EntityManager errors.php bin/console doctrine:schema:drop --force
Debug Mode Misuse
debug: true blocks all sends. Forgetting to disable it in production will silently fail SMS delivery.Character Limits
$this->turbosms->send(str_repeat("a", 100), "+380991234567");
Sender Restrictions
Enable SOAP Logging
Add to config.yml:
avator_turbosms:
soap_debug: true
Logs appear in var/log/dev.log.
Check Database Logs Query failed sends:
SELECT * FROM avator_turbosms_message WHERE status = 'failed';
Test Credentials Validate login/password with Turbosms’ test API or their web panel first.
Custom Message Class
Extend AVATOR\TurbosmsBundle\Entity\Message to add fields (e.g., template_id):
namespace AppBundle\Entity;
use AVATOR\TurbosmsBundle\Entity\Message as BaseMessage;
class Message extends BaseMessage {
protected $templateId;
// Add getters/setters
}
Update the bundle’s Message entity mapping in Resources/config/doctrine/Message.orm.yml.
Override Service
Replace the default service in services.yml:
services:
avator_turbosms.turbosms:
class: AppBundle\Service\CustomTurbosmsService
arguments: ['@avator_turbosms.client']
Add Pre/Post-Send Hooks Use Symfony events (if the bundle supports them). Example listener:
namespace AppBundle\EventListener;
use AVATOR\TurbosmsBundle\Event\PostSendEvent;
class TurbosmsListener {
public function onPostSend(PostSendEvent $event) {
if (!$event->isSuccess()) {
// Trigger fallback (e.g., email)
}
}
}
Localization
Override translation files in Resources/translations/ to customize error messages.
$em = $this->getDoctrine()->getManager();
$em->beginTransaction();
try {
foreach ($phones as $phone) {
$this->turbosms->send("Message", $phone);
}
$em->commit();
} catch (\Exception $e) {
$em->rollBack();
throw $e;
}
$client = $this->get('avator_turbosms.client');
// Reuse $client across requests
How can I help you explore Laravel packages today?