|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) Dennis Meckel |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, |
|
7
|
|
|
* please view the LICENSE file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Rayne\Ecoji; |
|
11
|
|
|
|
|
12
|
|
|
use InvalidArgumentException; |
|
13
|
|
|
use OutOfBoundsException; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Mapping implementation with the default emoji set defined by the "Ecoji Standard". |
|
17
|
|
|
* |
|
18
|
|
|
* @see https://github.com/keith-turner/ecoji |
|
19
|
|
|
*/ |
|
20
|
3 |
|
class EmojiMapping implements EmojiMappingInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var string[] `Map<ID, Emoji>` |
|
24
|
|
|
*/ |
|
25
|
|
|
private $emojis; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var int[] `Map<Emoji, ID>` |
|
29
|
|
|
*/ |
|
30
|
|
|
private $revEmojis; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $padding = '☕'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
private $padding40 = '⚜'; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
private $padding41 = '🏍'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
private $padding42 = '📑'; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
private $padding43 = '🙋'; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* |
|
59
|
|
|
*/ |
|
60
|
4292 |
|
public function __construct() |
|
61
|
|
|
{ |
|
62
|
4292 |
|
$this->emojis = require dirname(__DIR__) . '/assets/emojis.php'; |
|
63
|
|
|
|
|
64
|
4292 |
|
$this->revEmojis = array_flip($this->emojis); |
|
65
|
4292 |
|
$this->revEmojis[$this->padding] = 0; |
|
66
|
4292 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @inheritdoc |
|
70
|
|
|
*/ |
|
71
|
2124 |
|
public function getEmoji(int $id): string |
|
72
|
|
|
{ |
|
73
|
2124 |
|
if (!isset($this->emojis[$id])) { |
|
74
|
8 |
|
throw new OutOfBoundsException('Invalid ID: ' . $id); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
2116 |
|
return $this->emojis[$id]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @inheritdoc |
|
82
|
|
|
*/ |
|
83
|
2124 |
|
public function getId(string $emoji): int |
|
84
|
|
|
{ |
|
85
|
2124 |
|
if (!isset($this->revEmojis[$emoji])) { |
|
86
|
8 |
|
throw new InvalidArgumentException('Invalid rune: ' . $emoji); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
2116 |
|
return $this->revEmojis[$emoji]; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @inheritdoc |
|
94
|
|
|
*/ |
|
95
|
3188 |
|
public function getPadding(): string |
|
96
|
|
|
{ |
|
97
|
3188 |
|
return $this->padding; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @inheritdoc |
|
102
|
|
|
*/ |
|
103
|
2364 |
|
public function getPadding40(): string |
|
104
|
|
|
{ |
|
105
|
2364 |
|
return $this->padding40; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @inheritdoc |
|
110
|
|
|
*/ |
|
111
|
2148 |
|
public function getPadding41(): string |
|
112
|
|
|
{ |
|
113
|
2148 |
|
return $this->padding41; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @inheritdoc |
|
118
|
|
|
*/ |
|
119
|
1868 |
|
public function getPadding42(): string |
|
120
|
|
|
{ |
|
121
|
1868 |
|
return $this->padding42; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @inheritdoc |
|
126
|
|
|
*/ |
|
127
|
1596 |
|
public function getPadding43(): string |
|
128
|
|
|
{ |
|
129
|
1596 |
|
return $this->padding43; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|