The bundle provides new Doctrine type and Schema to simplify the way you store the Subscription
objects with Doctrine.
To enable this feature, the following configuration option shall be set:
This will tell the bundle to register the Subscription object as a Doctrine mapped-superclass. The DoctrineBundle shall be enabled. No additional configuration is required.
Subscription
EntityFirst of all, we need to create a Subscription Entity that extends the Subscription object. In this example, we also need to associate one or more Subscription entities to a specific user (Many To One relationship).
In this exaple, we assume you already have a valid User entity class.
User
EntityNow, to have a bidirectional relationship between this class and the User entity class, we will add this relationship to the User class.
Now that your entities are set, you can register Subcriptions and assign them to your users. To send a Notification to a specific user, you just have to get all subscriptions using $user->getSubscriptions()
.
It is possible to use your own Subscription entity class. The only constraint is that it shall implement the interface WebPush\SubscriptionInterface
or shall have a method that returns an object that implements this interface.