1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* Copyright (C) |
6
|
|
|
* Nathan Boiron <[email protected]> |
7
|
|
|
* Romain Canon <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This file is part of the TYPO3 NotiZ project. |
10
|
|
|
* It is free software; you can redistribute it and/or modify it |
11
|
|
|
* under the terms of the GNU General Public License, either |
12
|
|
|
* version 3 of the License, or any later version. |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, see: |
15
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Service; |
19
|
|
|
|
20
|
|
|
use CuyZ\Notiz\Core\Channel\Payload; |
21
|
|
|
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Data\SlackChannel; |
22
|
|
|
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\EntitySlackNotification; |
23
|
|
|
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Settings\EntitySlackSettings; |
24
|
|
|
|
25
|
|
|
class EntitySlackChannelMapper |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var EntitySlackNotification |
29
|
|
|
*/ |
30
|
|
|
private $notification; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var EntitySlackSettings |
34
|
|
|
*/ |
35
|
|
|
private $notificationSettings; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param Payload $payload |
39
|
|
|
*/ |
40
|
|
|
public function __construct(Payload $payload) |
41
|
|
|
{ |
42
|
|
|
$this->notification = $payload->getNotification(); |
|
|
|
|
43
|
|
|
$this->notificationSettings = $payload->getNotificationDefinition()->getSettings(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Returns an array of channels from a custom one and/or from one or |
48
|
|
|
* more defined ones. |
49
|
|
|
* |
50
|
|
|
* @return SlackChannel[] |
51
|
|
|
*/ |
52
|
|
|
public function getChannels(): array |
53
|
|
|
{ |
54
|
|
|
$channels = []; |
55
|
|
|
|
56
|
|
|
if ($this->notification->hasCustomSlackChannel()) { |
57
|
|
|
$channels[] = SlackChannel::fromNotification($this->notification); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$identifiers = explode(',', $this->notification->getSlackChannel()); |
61
|
|
|
|
62
|
|
|
foreach ($identifiers as $identifier) { |
63
|
|
|
if (!$this->notificationSettings->hasChannel($identifier)) { |
64
|
|
|
continue; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$channels[] = SlackChannel::fromDefinition( |
68
|
|
|
$this->notificationSettings->getChannel($identifier) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $channels; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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..