1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace UnicornFail\Emoji\Extension\Twemoji; |
6
|
|
|
|
7
|
|
|
use Dflydev\DotAccessData\Data; |
8
|
|
|
use League\Configuration\ConfigurationBuilderInterface; |
9
|
|
|
use Nette\Schema\Expect; |
10
|
|
|
use UnicornFail\Emoji\Environment\EnvironmentBuilderInterface; |
11
|
|
|
use UnicornFail\Emoji\Event\DocumentParsedEvent; |
12
|
|
|
use UnicornFail\Emoji\Extension\ConfigurableExtensionInterface; |
13
|
|
|
use UnicornFail\Emoji\Extension\ConfigureConversionTypesInterface; |
14
|
|
|
|
15
|
|
|
final class TwemojiExtension implements ConfigurableExtensionInterface, ConfigureConversionTypesInterface |
16
|
|
|
{ |
17
|
|
|
public const CONVERSION_TYPE = TwemojiProcessor::CONVERSION_TYPE; |
18
|
|
|
|
19
|
|
|
/** @var bool */ |
20
|
|
|
private $setAsDefaultConversionType; |
21
|
|
|
|
22
|
|
|
public function __construct(bool $setAsDefaultConversionType = true) |
23
|
|
|
{ |
24
|
|
|
$this->setAsDefaultConversionType = $setAsDefaultConversionType; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritDoc} |
29
|
|
|
*/ |
30
|
|
|
public function configureConversionTypes(string &$default, array &$conversionTypes, Data $rawConfig): void |
31
|
|
|
{ |
32
|
|
|
// Set the default conversion type to Twemoji. |
33
|
|
|
if ($this->setAsDefaultConversionType) { |
34
|
|
|
$default = TwemojiProcessor::CONVERSION_TYPE; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$conversionTypes[] = TwemojiProcessor::CONVERSION_TYPE; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function configureSchema(ConfigurationBuilderInterface $builder, Data $rawConfig): void |
41
|
|
|
{ |
42
|
|
|
$builder->addSchema('twemoji', Expect::structure([ |
43
|
|
|
'classes' => Expect::arrayOf('string')->default(['twemoji']), |
44
|
|
|
'classPrefix' => Expect::string('twemoji-')->nullable(), |
45
|
|
|
'icon' => Expect::bool(false)->nullable(), |
46
|
|
|
'inline' => Expect::bool(true), |
47
|
|
|
'size' => Expect::type('int|float|string')->nullable(), |
48
|
|
|
'type' => Expect::anyOf('png', 'svg')->default('svg'), |
49
|
|
|
'urlBase' => Expect::string('https://twemoji.maxcdn.com/v/latest'), |
50
|
|
|
])); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function register(EnvironmentBuilderInterface $environment): void |
54
|
|
|
{ |
55
|
|
|
$environment->addEventListener(DocumentParsedEvent::class, new TwemojiProcessor()); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|