1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Erdemkeren\JetSms; |
4
|
|
|
|
5
|
|
|
use Erdemkeren\JetSms\Http\Clients\JetSmsClientInterface; |
6
|
|
|
use Erdemkeren\JetSms\Http\Responses\JetSmsResponseInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class JetSmsService. |
10
|
|
|
*/ |
11
|
|
|
final class JetSmsService |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The jet sms client implementation. |
15
|
|
|
* |
16
|
|
|
* @var JetSmsClientInterface |
17
|
|
|
*/ |
18
|
|
|
private $client; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The short message factory implementation. |
22
|
|
|
* |
23
|
|
|
* @var ShortMessageFactoryInterface |
24
|
|
|
*/ |
25
|
|
|
private $factory; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The short message collection factory implementation. |
29
|
|
|
* |
30
|
|
|
* @var ShortMessageFactoryInterface |
31
|
|
|
*/ |
32
|
|
|
private $collectionFactory; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* JetSmsService constructor. |
36
|
|
|
* |
37
|
|
|
* @param JetSmsClientInterface $jetSmsClient |
38
|
|
|
* @param ShortMessageFactoryInterface $shortMessageFactory |
39
|
|
|
* @param ShortMessageCollectionFactoryInterface $shortMessageCollectionFactory |
40
|
|
|
*/ |
41
|
3 |
|
public function __construct( |
42
|
|
|
JetSmsClientInterface $jetSmsClient, |
43
|
|
|
ShortMessageFactoryInterface $shortMessageFactory, |
44
|
|
|
ShortMessageCollectionFactoryInterface $shortMessageCollectionFactory |
45
|
|
|
) { |
46
|
3 |
|
$this->client = $jetSmsClient; |
47
|
3 |
|
$this->factory = $shortMessageFactory; |
48
|
3 |
|
$this->collectionFactory = $shortMessageCollectionFactory; |
|
|
|
|
49
|
3 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Send the given body to the given receivers. |
53
|
|
|
* |
54
|
|
|
* @param string $body The body of the short message. |
55
|
|
|
* @param array|string $receivers The receiver(s) of the message. |
56
|
|
|
* |
57
|
|
|
* @return JetSmsResponseInterface The parsed JetSms response object. |
58
|
|
|
*/ |
59
|
2 |
|
public function sendShortMessage($receivers, $body) |
60
|
|
|
{ |
61
|
2 |
|
$shortMessage = $this->factory->create($receivers, $body); |
62
|
|
|
|
63
|
2 |
|
return $this->client->sendShortMessage($shortMessage); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Send the given short messages. |
68
|
|
|
* |
69
|
|
|
* @param array $messages An array containing short message arrays. |
70
|
|
|
* |
71
|
|
|
* @return JetSmsResponseInterface The parsed JetSms response object. |
72
|
|
|
*/ |
73
|
1 |
|
public function sendShortMessages(array $messages) |
74
|
|
|
{ |
75
|
1 |
|
$collection = $this->collectionFactory->create(); |
|
|
|
|
76
|
|
|
|
77
|
1 |
|
foreach ($messages as $message) { |
78
|
1 |
|
$collection->push($this->factory->create( |
|
|
|
|
79
|
1 |
|
$message['recipient'], |
80
|
1 |
|
$message['message'] |
81
|
1 |
|
)); |
82
|
1 |
|
} |
83
|
|
|
|
84
|
1 |
|
return $this->client->sendShortMessages($collection); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..