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
|
|
|
/** |
20
|
|
|
* {@inheritDoc} |
21
|
|
|
*/ |
22
|
|
|
public function configureConversionTypes(string &$default, array &$conversionTypes, Data $rawConfig): void |
23
|
|
|
{ |
24
|
|
|
// Set the default conversion type to Twemoji. |
25
|
|
|
if (! $rawConfig->has('twemoji.defaultConversionType') || $rawConfig->get('twemoji.defaultConversionType') === true) { |
26
|
|
|
$default = TwemojiProcessor::CONVERSION_TYPE; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$conversionTypes[] = TwemojiProcessor::CONVERSION_TYPE; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function configureSchema(ConfigurationBuilderInterface $builder, Data $rawConfig): void |
33
|
|
|
{ |
34
|
|
|
$builder->addSchema('twemoji', Expect::structure([ |
35
|
|
|
'defaultConversionType' => Expect::bool(true), |
36
|
|
|
'classes' => Expect::arrayOf('string')->default(['twemoji']), |
37
|
|
|
'classPrefix' => Expect::string('twemoji-')->nullable(), |
38
|
|
|
'icon' => Expect::bool(false)->nullable(), |
39
|
|
|
'inlineSvg' => Expect::bool(true), |
40
|
|
|
'size' => Expect::int()->nullable(), |
41
|
|
|
'type' => Expect::anyOf('png', 'svg')->default('svg'), |
42
|
|
|
'urlBase' => Expect::string('https://twemoji.maxcdn.com/v/latest'), |
43
|
|
|
])); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function register(EnvironmentBuilderInterface $environment): void |
47
|
|
|
{ |
48
|
|
|
$environment->addEventListener(DocumentParsedEvent::class, new TwemojiProcessor()); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|