Skip to content

Commit 2e5f526

Browse files
authored
Merge pull request #19 from sendinblue/feature_fix-enum-for-type-array
Fix enum for array type in create/update webhook models
2 parents 8bfb4ba + 1633c57 commit 2e5f526

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

lib/Model/CreateWebhook.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,47 @@ public static function getters()
131131
return self::$getters;
132132
}
133133

134+
const EVENTS_HARD_BOUNCE = 'hardBounce';
135+
const EVENTS_SOFT_BOUNCE = 'softBounce';
136+
const EVENTS_BLOCKED = 'blocked';
137+
const EVENTS_SPAM = 'spam';
138+
const EVENTS_DELIVERED = 'delivered';
139+
const EVENTS_REQUEST = 'request';
140+
const EVENTS_CLICK = 'click';
141+
const EVENTS_INVALID = 'invalid';
142+
const EVENTS_DEFERRED = 'deferred';
143+
const EVENTS_OPENED = 'opened';
144+
const EVENTS_UNIQUE_OPENED = 'uniqueOpened';
145+
const EVENTS_UNSUBSCRIBED = 'unsubscribed';
146+
const EVENTS_LIST_ADDITION = 'listAddition';
134147
const TYPE_TRANSACTIONAL = 'transactional';
135148
const TYPE_MARKETING = 'marketing';
136149

137150

138151

152+
/**
153+
* Gets allowable values of the enum
154+
* @return string[]
155+
*/
156+
public function getEventsAllowableValues()
157+
{
158+
return [
159+
self::EVENTS_HARD_BOUNCE,
160+
self::EVENTS_SOFT_BOUNCE,
161+
self::EVENTS_BLOCKED,
162+
self::EVENTS_SPAM,
163+
self::EVENTS_DELIVERED,
164+
self::EVENTS_REQUEST,
165+
self::EVENTS_CLICK,
166+
self::EVENTS_INVALID,
167+
self::EVENTS_DEFERRED,
168+
self::EVENTS_OPENED,
169+
self::EVENTS_UNIQUE_OPENED,
170+
self::EVENTS_UNSUBSCRIBED,
171+
self::EVENTS_LIST_ADDITION,
172+
];
173+
}
174+
139175
/**
140176
* Gets allowable values of the enum
141177
* @return string[]
@@ -268,6 +304,15 @@ public function getEvents()
268304
*/
269305
public function setEvents($events)
270306
{
307+
$allowed_values = $this->getEventsAllowableValues();
308+
if (!is_null($events) && array_diff($events, $allowed_values)) {
309+
throw new \InvalidArgumentException(
310+
sprintf(
311+
"Invalid value for 'events', must be one of '%s'",
312+
implode("', '", $allowed_values)
313+
)
314+
);
315+
}
271316
$this->container['events'] = $events;
272317

273318
return $this;

lib/Model/UpdateWebhook.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,45 @@ public static function getters()
126126
return self::$getters;
127127
}
128128

129+
const EVENTS_HARD_BOUNCE = 'hardBounce';
130+
const EVENTS_SOFT_BOUNCE = 'softBounce';
131+
const EVENTS_BLOCKED = 'blocked';
132+
const EVENTS_SPAM = 'spam';
133+
const EVENTS_DELIVERED = 'delivered';
134+
const EVENTS_REQUEST = 'request';
135+
const EVENTS_CLICK = 'click';
136+
const EVENTS_INVALID = 'invalid';
137+
const EVENTS_DEFERRED = 'deferred';
138+
const EVENTS_OPENED = 'opened';
139+
const EVENTS_UNIQUE_OPENED = 'uniqueOpened';
140+
const EVENTS_UNSUBSCRIBED = 'unsubscribed';
141+
const EVENTS_LIST_ADDITION = 'listAddition';
129142

130143

131144

145+
/**
146+
* Gets allowable values of the enum
147+
* @return string[]
148+
*/
149+
public function getEventsAllowableValues()
150+
{
151+
return [
152+
self::EVENTS_HARD_BOUNCE,
153+
self::EVENTS_SOFT_BOUNCE,
154+
self::EVENTS_BLOCKED,
155+
self::EVENTS_SPAM,
156+
self::EVENTS_DELIVERED,
157+
self::EVENTS_REQUEST,
158+
self::EVENTS_CLICK,
159+
self::EVENTS_INVALID,
160+
self::EVENTS_DEFERRED,
161+
self::EVENTS_OPENED,
162+
self::EVENTS_UNIQUE_OPENED,
163+
self::EVENTS_UNSUBSCRIBED,
164+
self::EVENTS_LIST_ADDITION,
165+
];
166+
}
167+
132168

133169
/**
134170
* Associative array for storing property values
@@ -230,6 +266,15 @@ public function getEvents()
230266
*/
231267
public function setEvents($events)
232268
{
269+
$allowed_values = $this->getEventsAllowableValues();
270+
if (!is_null($events) && array_diff($events, $allowed_values)) {
271+
throw new \InvalidArgumentException(
272+
sprintf(
273+
"Invalid value for 'events', must be one of '%s'",
274+
implode("', '", $allowed_values)
275+
)
276+
);
277+
}
233278
$this->container['events'] = $events;
234279

235280
return $this;

0 commit comments

Comments
 (0)