1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupGateway\ApiBundle\Service; |
20
|
|
|
|
21
|
|
|
use Psr\Log\LoggerInterface; |
22
|
|
|
use Surfnet\MessageBirdApiClient\Messaging\Message; |
23
|
|
|
use Surfnet\MessageBirdApiClient\Messaging\SendMessageResult; |
24
|
|
|
use Surfnet\MessageBirdApiClientBundle\Service\MessagingService; |
25
|
|
|
use Surfnet\StepupGateway\ApiBundle\Dto\Requester; |
26
|
|
|
use Surfnet\StepupGateway\ApiBundle\Dto\SmsMessage; |
27
|
|
|
|
28
|
|
|
class SmsService |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var MessagingService |
32
|
|
|
*/ |
33
|
|
|
private $messagingService; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var LoggerInterface |
37
|
|
|
*/ |
38
|
|
|
private $logger; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param MessagingService $messagingService |
42
|
|
|
* @param LoggerInterface $logger |
43
|
|
|
*/ |
44
|
|
|
public function __construct(MessagingService $messagingService, LoggerInterface $logger) |
45
|
|
|
{ |
46
|
|
|
$this->messagingService = $messagingService; |
47
|
|
|
$this->logger = $logger; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param SmsMessage $message |
52
|
|
|
* @param Requester $requester |
53
|
|
|
* @return SendMessageResult |
54
|
|
|
*/ |
55
|
|
|
public function send(SmsMessage $message, Requester $requester) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$this->logger->notice('Sending OTP per SMS.'); |
58
|
|
|
|
59
|
|
|
$message = new Message($message->originator, $message->recipient, $message->body); |
60
|
|
|
$result = $this->messagingService->send($message); |
61
|
|
|
|
62
|
|
|
if (!$result->isSuccess()) { |
63
|
|
|
$this->logger->warning('Sending OTP per SMS failed.'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $result; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.