Completed
Push — master ( b123ad...2604a0 )
by Joachim
02:07
created

WebhookExchange::setWebhookQueueItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
8
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
9
use Symfony\Component\Validator\Constraints as Assert;
10
11
/**
12
 * We use the terminology from Message Queues where an exchange is where we publish events.
13
 *
14
 * @ORM\Table(name="dandomain_altapay_webhook_exchanges")
15
 * @ORM\Entity()
16
 * @UniqueEntity("url")
17
 */
18
class WebhookExchange
19
{
20
    use ORMBehaviors\Timestampable\Timestampable;
21
22
    /**
23
     * @var int
24
     *
25
     * @ORM\Id
26
     * @ORM\Column(name="id", type="integer")
27
     * @ORM\GeneratedValue(strategy="AUTO")
28
     */
29
    private $id;
30
31
    /**
32
     * This will hold the URL to where the events are published.
33
     *
34
     * @var string
35
     *
36
     * @Assert\NotBlank()
37
     * @Assert\Length(max="191")
38
     * @Assert\Url()
39
     *
40
     * @ORM\Column(type="string", unique=true, length=191)
41
     */
42
    private $url;
43
44
    /**
45
     * This will hold the last event id published.
46
     *
47
     * @var int
48
     *
49
     * @Assert\GreaterThanOrEqual(0)
50
     *
51
     * @ORM\Column(type="integer")
52
     */
53
    private $lastEventId;
54
55
    /**
56
     * @var ArrayCollection|WebhookQueueItem[]
57
     *
58
     * @ORM\OneToMany(targetEntity="WebhookQueueItem", mappedBy="webhookExchange", cascade={"persist", "remove"})
59
     */
60
    private $webhookQueueItems;
61
62
    public function __construct(string $url, int $lastEventId = 0)
63
    {
64
        $this->setUrl($url);
65
        $this->setLastEventId($lastEventId);
66
        $this->webhookQueueItems = new ArrayCollection();
67
    }
68
69
    /**
70
     * @return int
71
     */
72
    public function getId(): ?int
73
    {
74
        return $this->id;
75
    }
76
77
    /**
78
     * @param int $id
79
     *
80
     * @return WebhookExchange
81
     */
82
    public function setId(int $id): self
83
    {
84
        $this->id = $id;
85
86
        return $this;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getUrl(): string
93
    {
94
        return $this->url;
95
    }
96
97
    /**
98
     * @param string $url
99
     *
100
     * @return WebhookExchange
101
     */
102
    public function setUrl(string $url): self
103
    {
104
        $this->url = $url;
105
106
        return $this;
107
    }
108
109
    /**
110
     * @return int
111
     */
112
    public function getLastEventId(): int
113
    {
114
        return $this->lastEventId;
115
    }
116
117
    /**
118
     * @param int $lastEventId
119
     *
120
     * @return WebhookExchange
121
     */
122
    public function setLastEventId(int $lastEventId): self
123
    {
124
        $this->lastEventId = $lastEventId;
125
126
        return $this;
127
    }
128
129
    /**
130
     * @return WebhookQueueItem[]|ArrayCollection
131
     */
132
    public function getWebhookQueueItems(): ArrayCollection
133
    {
134
        return $this->webhookQueueItems;
135
    }
136
137
    /**
138
     * @param ArrayCollection $webhookQueueItems
139
     *
140
     * @return WebhookExchange
141
     */
142
    public function setWebhookQueueItems(ArrayCollection $webhookQueueItems)
143
    {
144
        $this->webhookQueueItems = $webhookQueueItems;
145
146
        return $this;
147
    }
148
149
    /**
150
     * @param WebhookQueueItem $webhookQueueItem
151
     *
152
     * @return WebhookExchange
153
     */
154
    public function addWebhookQueueItem(WebhookQueueItem $webhookQueueItem): self
155
    {
156
        $webhookQueueItem->setWebhookExchange($this);
157
        $this->webhookQueueItems->add($webhookQueueItem);
158
159
        return $this;
160
    }
161
}
162