Installation:
composer require cmnty/push-bundle
Add to AppKernel.php (Symfony 2/3):
new Cmnty\PushBundle\CmntyPushBundle(),
Basic Configuration (config/packages/cmnty_push.yaml):
cmnty_push:
push_services:
google:
enabled: true
api_key: "%env(GCM_API_KEY)%"
First Use Case:
Inject the Cmnty\PushBundle\Service\PushService and send a notification:
use Cmnty\PushBundle\Service\PushService;
class MyController {
public function __construct(private PushService $pushService) {}
public function sendNotification() {
$notification = new \Cmnty\Push\Notification('Hello World!');
$endPoint = new \Cmnty\Push\EndPoint('device_token_here');
$this->pushService->send($endPoint, $notification);
}
}
Service Integration:
PushService in controllers/services.cmnty_push.push_services.Subscription Management:
PushSubscription embeddable:
doctrine:
orm:
mappings:
PushSubscription: { type: xml, dir: "%kernel.root_dir%/../vendor/cmnty/push-bundle/src/Resources/config/embeddable" }
use Cmnty\Push\EndPoint;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class UserDevice {
#[ORM\Embedded(class: 'Cmnty\Push\EndPoint')]
private $endPoint;
}
Batch Sending:
foreach ($userDevices as $device) {
$this->pushService->send($device->getEndPoint(), $notification);
}
Custom Notifications:
\Cmnty\Push\Notification for payload customization:
class CustomNotification extends Notification {
public function __construct(string $message, array $customData) {
parent::__construct($message);
$this->setData($customData);
}
}
.env (e.g., GCM_API_KEY).send() calls in try-catch to handle failed deliveries:
try {
$this->pushService->send($endPoint, $notification);
} catch (\Cmnty\Push\Exception\PushException $e) {
// Log or retry logic
}
Deprecated Bundle:
symfony/push-notification for modern projects.Doctrine Mapping Issues:
binary_string DBAL type may cause conflicts with existing projects. Test thoroughly.PushSubscription mappings are correctly referenced in config/packages/doctrine.yaml.Configuration Quirks:
enabled: true is not auto-set if api_key is missing. Explicitly configure required services.enabled: true—disable if unused to avoid unnecessary overhead.Crypto Dependencies:
cmnty/push library relies on openssl. Ensure your server has OpenSSL support.monolog:
handlers:
main:
level: debug
Custom Push Services:
\Cmnty\PushBundle\Service\PushService to add new providers (e.g., Firebase):
class FirebasePushService extends PushService {
protected function getProvider(): \Cmnty\Push\Provider\ProviderInterface {
return new \Cmnty\Push\Provider\FirebaseProvider($this->apiKey);
}
}
services.yaml:
services:
App\Service\FirebasePushService:
arguments: ['%env(FIREBASE_API_KEY)%']
tags: ['cmnty_push.service']
Event Listeners:
cmnty_push.send) to log or analyze deliveries:
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PushEventSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
'cmnty_push.send' => 'onPushSent',
];
}
public function onPushSent(\Cmnty\PushBundle\Event\PushEvent $event) {
// Custom logic
}
}
Fallback Mechanisms:
Messenger component:
$this->messenger->dispatch(new RetryPushMessage($endPoint, $notification));
How can I help you explore Laravel packages today?