symfony/spot-hit-notifier
Symfony Notifier transport for Spot-Hit SMS. Configure via SPOTHIT_DSN with your API token and sender (from), with optional settings for long SMS and concatenation count validation. Links to Spot-Hit API docs and Symfony issue/PR channels.
Installation
composer require symfony/spot-hit-notifier
Verify the package is autoloaded in composer.json under autoload.psr-4.
Configuration
Add the bundle to config/bundles.php (Symfony) or register the service provider in config/app.php (Laravel via Symfony bridge):
// Laravel (via Symfony bridge)
$provider = new \Symfony\Component\HttpKernel\KernelEvents::class;
$this->app->register(\Symfony\SpotHitNotifier\SpotHitNotifierBundle::class);
First Use Case Trigger a notification in a controller or service:
use Symfony\Component\SpotHitNotifier\SpotHitNotifier;
public function sendNotification()
{
$notifier = app(SpotHitNotifier::class);
$notifier->send('user@example.com', 'Welcome!', 'Your account is ready.');
return response()->json(['success' => true]);
}
Event-Driven Notifications
Hook into Laravel events (e.g., Illuminate\Auth\Events\Registered) to send automated alerts:
use Illuminate\Support\Facades\Event;
use Symfony\Component\SpotHitNotifier\SpotHitNotifier;
Event::listen('Illuminate\Auth\Events\Registered', function ($user) {
$notifier = app(SpotHitNotifier::class);
$notifier->send($user->email, 'Registration Confirmation', 'Verify your email...');
});
Template-Based Emails Use Twig templates (if integrated) for dynamic content:
$notifier->sendTwig('user@example.com', 'Welcome', 'emails/welcome.twig', [
'name' => 'John Doe',
]);
Batch Processing Queue notifications for async delivery (Laravel Queue integration):
$notifier->queueSend('user@example.com', 'Digest', 'Your weekly update...');
Mail facade for unified email handling.try-catch to log failures:
try {
$notifier->send($email, $subject, $body);
} catch (\Exception $e) {
\Log::error("Notification failed: " . $e->getMessage());
}
config/services.php:
'spot_hit_notifier' => [
'api_key' => env('SPOT_HIT_API_KEY'),
'default_from' => 'noreply@example.com',
],
API Key Management
.env:
SPOT_HIT_API_KEY=your_key_here
.env to version control.Rate Limits
$attempts = 0;
while ($attempts < 3) {
try {
$notifier->send(...);
break;
} catch (\Symfony\Component\SpotHitNotifier\Exception\RateLimitExceeded $e) {
sleep(2 ** $attempts);
$attempts++;
}
}
Template Caching
php artisan view:clear
SPOT_HIT_DEBUG=true in .env to log API responses.Mockery to stub the notifier:
$mock = Mockery::mock(SpotHitNotifier::class);
$mock->shouldReceive('send')->once();
$this->app->instance(SpotHitNotifier::class, $mock);
Custom Transport
Extend Symfony\Component\SpotHitNotifier\Transport\TransportInterface to support additional channels (e.g., SMS):
class CustomTransport implements TransportInterface {
public function send(Notification $notification) {
// Custom logic (e.g., Twilio API)
}
}
Event Listeners
Subscribe to SpotHitNotifierEvents for pre/post-send hooks:
use Symfony\Component\SpotHitNotifier\Event\NotificationSentEvent;
Event::listen(NotificationSentEvent::class, function ($event) {
\Log::info("Sent to {$event->getRecipient()}");
});
Laravel Notifications
Bridge with Laravel’s Notifiable trait for unified notifications:
use Illuminate\Notifications\Notifiable;
use Symfony\Component\SpotHitNotifier\SpotHitChannel;
class User extends Model implements Notifiable {
public function routeNotificationForSpotHit() {
return $this->email;
}
}
How can I help you explore Laravel packages today?