|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace UnicornFail\Emoji\Node\Inline; |
|
6
|
|
|
|
|
7
|
|
|
use UnicornFail\Emoji\Dataset\Emoji; |
|
8
|
|
|
use UnicornFail\Emoji\Emojibase\EmojibaseDatasetInterface; |
|
9
|
|
|
use UnicornFail\Emoji\Node\EmojiContainerInterface; |
|
10
|
|
|
use UnicornFail\Emoji\Parser\Lexer; |
|
11
|
|
|
|
|
12
|
|
|
abstract class AbstractEmoji extends AbstractStringContainer implements EmojiContainerInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var string */ |
|
15
|
|
|
private $convertTo = Lexer::UNICODE; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string[] */ |
|
18
|
|
|
private $excludedShortcodes = []; |
|
19
|
|
|
|
|
20
|
|
|
/** @var Emoji */ |
|
21
|
|
|
private $emoji; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
private $parsedValue; |
|
25
|
|
|
|
|
26
|
|
|
/** @var ?int */ |
|
27
|
|
|
private $presentationMode = EmojibaseDatasetInterface::EMOJI; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct(string $value, Emoji $emoji) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct($value); |
|
32
|
|
|
$this->emoji = $emoji; |
|
33
|
|
|
$this->parsedValue = $value; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getEmoji(): Emoji |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->emoji; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getLiteral(): string |
|
42
|
|
|
{ |
|
43
|
|
|
$emoji = $this->getEmoji(); |
|
44
|
|
|
|
|
45
|
|
|
if ($this->convertTo === Lexer::EMOTICON && $emoji->emoticon) { |
|
46
|
|
|
return $emoji->emoticon; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if ($this->convertTo === Lexer::HTML_ENTITY && $emoji->htmlEntity) { |
|
50
|
|
|
return $emoji->htmlEntity; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if ($this->convertTo === Lexer::SHORTCODE && ($shortcode = $emoji->getShortcode($this->excludedShortcodes, true))) { |
|
54
|
|
|
return $shortcode; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (($this->presentationMode ?? $emoji->type) === EmojibaseDatasetInterface::TEXT && $emoji->text) { |
|
58
|
|
|
return $emoji->text; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $emoji->emoji ?? parent::getLiteral(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getParsedValue(): string |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->parsedValue; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param string[] $excludedShortcodes |
|
71
|
|
|
*/ |
|
72
|
|
|
public function setExcludedShortcodes(array $excludedShortcodes = []): void |
|
73
|
|
|
{ |
|
74
|
|
|
$this->excludedShortcodes = $excludedShortcodes; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function setPresentationMode(?int $presentationMode = null): void |
|
78
|
|
|
{ |
|
79
|
|
|
$this->presentationMode = $presentationMode; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function setConvertTo(string $convertTo): void |
|
83
|
|
|
{ |
|
84
|
|
|
$this->convertTo = $convertTo; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|