forked from utopia-php/messaging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPush.php
More file actions
45 lines (38 loc) · 1.08 KB
/
Push.php
File metadata and controls
45 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Utopia\Messaging\Adapters;
use Utopia\Messaging\Adapter;
use Utopia\Messaging\Message;
use Utopia\Messaging\Messages\Push as PushMessage;
abstract class Push extends Adapter
{
public function getType(): string
{
return 'push';
}
public function getMessageType(): string
{
return PushMessage::class;
}
/**
* {@inheritdoc}
*
* @throws \Exception
*/
public function send(Message $message): string
{
if (! \is_a($message, $this->getMessageType())) {
throw new \Exception('Invalid message type.');
}
if (\count($message->getTo()) > $this->getMaxMessagesPerRequest()) {
throw new \Exception("{$this->getName()} can only send {$this->getMaxMessagesPerRequest()} messages per request.");
}
return $this->process($message);
}
/**
* Send a push message.
*
* @param PushMessage $message Message to process.
* @return string The response body.
*/
abstract protected function process(PushMessage $message): string;
}