|
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\DatasetInterface; |
|
9
|
|
|
use UnicornFail\Emoji\Environment\ConfigurableEnvironmentInterface; |
|
10
|
|
|
use UnicornFail\Emoji\Parser\Lexer; |
|
11
|
|
|
|
|
12
|
|
|
abstract class AbstractEmoji extends Text |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var string[] */ |
|
15
|
|
|
private $excludedShortcodes = []; |
|
16
|
|
|
|
|
17
|
|
|
/** @var Emoji */ |
|
18
|
|
|
private $emoji; |
|
19
|
|
|
|
|
20
|
|
|
/** @var ?int */ |
|
21
|
|
|
private $presentationMode = DatasetInterface::EMOJI; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
private $stringableType = Lexer::UNICODE; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(string $value, Emoji $emoji, ConfigurableEnvironmentInterface $environment) |
|
27
|
|
|
{ |
|
28
|
|
|
parent::__construct($value); |
|
29
|
|
|
$this->emoji = $emoji; |
|
30
|
|
|
|
|
31
|
|
|
/** @var string[] $excludedShortcodes */ |
|
32
|
|
|
$excludedShortcodes = $environment->getConfiguration()->get('exclude.shortcodes'); |
|
33
|
|
|
$this->setExcludedShortcodes($excludedShortcodes); |
|
34
|
|
|
|
|
35
|
|
|
/** @var ?int $presentation */ |
|
36
|
|
|
$presentation = $environment->getConfiguration()->get('presentation'); |
|
37
|
|
|
$this->setPresentationMode($presentation); |
|
38
|
|
|
|
|
39
|
|
|
$stringableType = (string) ($environment->getConfiguration()->get('stringableType') ?? Lexer::UNICODE); |
|
40
|
|
|
$this->setStringableType($stringableType); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getEmoji(): Emoji |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->emoji; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getLiteral(): string |
|
49
|
|
|
{ |
|
50
|
|
|
$value = parent::getLiteral(); |
|
51
|
|
|
|
|
52
|
|
|
$emoji = $this->getEmoji(); |
|
53
|
|
|
switch ($this->stringableType) { |
|
54
|
|
|
case Lexer::EMOTICON: |
|
55
|
|
|
return $emoji->emoticon ?? $value; |
|
56
|
|
|
case Lexer::HTML_ENTITY: |
|
57
|
|
|
return $emoji->htmlEntity ?? $value; |
|
58
|
|
|
case Lexer::SHORTCODE: |
|
59
|
|
|
return $emoji->getShortcode($this->excludedShortcodes, true) ?? $value; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (($this->presentationMode ?? $emoji->type) === DatasetInterface::TEXT) { |
|
63
|
|
|
return $emoji->text ?? $value; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $emoji->emoji ?? $value; |
|
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 setStringableType(string $stringableType): void |
|
83
|
|
|
{ |
|
84
|
|
|
$this->stringableType = $stringableType; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|