|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Model\Helpers\ChatNotificationInterface; |
|
6
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
|
7
|
|
|
use eXpansion\Framework\Core\Services\Console; |
|
8
|
|
|
use eXpansion\Framework\Core\Storage\PlayerStorage; |
|
9
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
10
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\UnknownPlayerException; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class ChatNotification |
|
14
|
|
|
* |
|
15
|
|
|
* @package eXpansion\Framework\Core\Helpers; |
|
16
|
|
|
* @author oliver de Cramer <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class ChatNotification implements ChatNotificationInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var Connection */ |
|
21
|
|
|
protected $connection; |
|
22
|
|
|
|
|
23
|
|
|
/** @var Translations */ |
|
24
|
|
|
protected $translations; |
|
25
|
|
|
|
|
26
|
|
|
/** @var PlayerStorage */ |
|
27
|
|
|
protected $playerStorage; |
|
28
|
|
|
|
|
29
|
|
|
/** @var Console */ |
|
30
|
|
|
protected $console; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* ChatNotification constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param Connection $connection |
|
36
|
|
|
* @param Translations $translations |
|
37
|
|
|
* @param PlayerStorage $playerStorage |
|
38
|
|
|
*/ |
|
39
|
7 |
|
public function __construct( |
|
40
|
|
|
Connection $connection, |
|
41
|
|
|
Translations $translations, |
|
42
|
|
|
PlayerStorage $playerStorage, |
|
43
|
|
|
Console $console |
|
44
|
|
|
) { |
|
45
|
7 |
|
$this->connection = $connection; |
|
46
|
7 |
|
$this->translations = $translations; |
|
47
|
7 |
|
$this->playerStorage = $playerStorage; |
|
48
|
7 |
|
$this->console = $console; |
|
49
|
7 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Send message. |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $messageId |
|
55
|
|
|
* @param string|string[]|Group|null $to |
|
56
|
|
|
* @param string[] $parameters |
|
57
|
|
|
*/ |
|
58
|
3 |
|
public function sendMessage($messageId, $to = null, $parameters = []) |
|
59
|
|
|
{ |
|
60
|
3 |
|
$message = $messageId; |
|
61
|
|
|
|
|
62
|
3 |
|
if (is_string($to)) { |
|
63
|
1 |
|
$player = $this->playerStorage->getPlayerInfo($to); |
|
64
|
1 |
|
$message = $this->translations->getTranslation($messageId, $parameters, strtolower($player->getLanguage())); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
3 |
|
if (is_array($to)) { |
|
68
|
1 |
|
$to = implode(",", $to); |
|
69
|
1 |
|
$message = $this->translations->getTranslations($messageId, $parameters); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
3 |
|
if ($to instanceof Group) { |
|
|
|
|
|
|
73
|
|
|
$to = implode(",", $to->getLogins()); |
|
74
|
|
|
$message = $this->translations->getTranslations($messageId, $parameters); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
3 |
|
if ($to === null || $to instanceof Group) { |
|
|
|
|
|
|
78
|
1 |
|
$message = $this->translations->getTranslations($messageId, $parameters); |
|
79
|
1 |
|
$this->console->writeln(end($message)['Text']); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
try { |
|
83
|
3 |
|
$this->connection->chatSendServerMessage($message, $to); |
|
|
|
|
|
|
84
|
2 |
|
} catch (UnknownPlayerException $e) { |
|
85
|
|
|
// Nothing to do, it happens. |
|
86
|
|
|
} |
|
87
|
1 |
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Return messageId with arguments as a string |
|
91
|
|
|
* Usage: used for retrieving partials for chat messages |
|
92
|
|
|
* * defaults to English locale, without parameters |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $messageId |
|
95
|
|
|
* @param array $parameters |
|
96
|
|
|
* @param string $locale |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function getMessage($messageId, $parameters = [], $locale = "en") |
|
100
|
|
|
{ |
|
101
|
1 |
|
return $this->translations->getTranslation($messageId, $parameters, $locale); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.