1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Shieldon package. |
4
|
|
|
* |
5
|
|
|
* (c) Terry L. <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace Shieldon\Firewall\Kernel; |
14
|
|
|
|
15
|
|
|
use Shieldon\Messenger\Messenger\MessengerInterface; |
16
|
|
|
use RuntimeException; |
17
|
|
|
|
18
|
|
|
/* |
19
|
|
|
* Messenger Trait is loaded in Kernel instance only. |
20
|
|
|
*/ |
21
|
|
|
trait MessengerTrait |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The ways Shieldon send a message to when someone has been blocked. |
25
|
|
|
* The collection of \Shieldon\Messenger\Messenger\MessengerInterface |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $messenger = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The message that will be sent to the third-party API. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $msgBody = ''; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Set a messenger |
40
|
|
|
* |
41
|
|
|
* @param MessengerInterfa $instance |
|
|
|
|
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function setMessenger(MessengerInterface $instance): void |
46
|
|
|
{ |
47
|
|
|
$class = $this->getClassName($instance); |
|
|
|
|
48
|
|
|
$this->messengers[$class] = $instance; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Set the message body. |
53
|
|
|
* |
54
|
|
|
* @param string $message The message text. |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
protected function setMessageBody(string $message = ''): void |
59
|
|
|
{ |
60
|
|
|
$this->msgBody = $message; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// @codeCoverageIgnoreStart |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Undocumented function |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
protected function triggerMessengers(): void |
71
|
|
|
{ |
72
|
|
|
if (empty($this->msgBody)) { |
73
|
|
|
return; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
try { |
77
|
|
|
foreach ($this->messenger as $messenger) { |
78
|
|
|
$messenger->setTimeout(2); |
79
|
|
|
$messenger->send($this->msgBody); |
80
|
|
|
} |
81
|
|
|
} catch (RuntimeException $e) { |
82
|
|
|
// Do not throw error, becasue the third-party services might be unavailable. |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// @codeCoverageIgnoreEnd |
87
|
|
|
} |
88
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths