Doctrine
Using The Doctrine Mapping
Configuration
webpush:
doctrine_mapping: trueThe Subscription Entity
Subscription Entity<?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use WebPush\Subscription as WebPushSubscription;
/**
* @ORM\Table(name="subscriptions")
* @ORM\Entity
*/
class Subscription extends WebPushSubscription
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="subscriptions", cascade={"persist"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable="true")
*/
private ?User $user;
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
// We need to override this method as it returns a WebPush\Subscription and we want an entity
public static function createFromString(string $input): self
{
$base = BaseSubscription::createFromString($input);
$object = new self($base->getEndpoint());
$object->withContentEncodings($base->getSupportedContentEncodings());
foreach ($base->getKeys()->all() as $k => $v) {
$object->getKeys()->set($k, $v);
}
return $object;
}
}The User Entity
User EntitySending Notifications To A User
Using Doctrine Type
Using Your Own Entity Class
Last updated
Was this helpful?