Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit643b9d2

Browse files
committed
[TwigBridge] Addemojify twig filter
1 parentfc97603 commit643b9d2

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

‎src/Symfony/Bridge/Twig/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Add`emojify` twig filter
8+
49
7.0
510
---
611

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bridge\Twig\Extension;
13+
14+
useSymfony\Component\Emoji\EmojiTransliterator;
15+
useTwig\Extension\AbstractExtension;
16+
useTwig\TwigFilter;
17+
18+
/**
19+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
20+
*/
21+
finalclass EmojiExtensionextends AbstractExtension
22+
{
23+
privatestaticarray$transliterators = [];
24+
25+
publicfunctiongetFilters():array
26+
{
27+
return [
28+
newTwigFilter('emojify',$this->emojify(...)),
29+
];
30+
}
31+
32+
publicfunctionemojify(string$string,string$catalog ='slack'):string
33+
{
34+
if (!in_array($catalog,$catalogs = ['slack','github'],true)) {
35+
thrownew \InvalidArgumentException(sprintf('The catalog "%s" is not supported. Try one among "%s".',$catalog,implode('", "',$catalogs)));
36+
}
37+
38+
$tr =self::$transliterators[$catalog] ??= EmojiTransliterator::create('emoji-'.$catalog, EmojiTransliterator::REVERSE);
39+
40+
return (string)$tr->transliterate($string);
41+
}
42+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bridge\Twig\Tests\Extension;
13+
14+
usePHPUnit\Framework\TestCase;
15+
useSymfony\Bridge\Twig\Extension\EmojiExtension;
16+
17+
class EmojiExtensionTestextends TestCase
18+
{
19+
/**
20+
* @testWith ["😂", ":joy:"]
21+
* ["😂", ":joy:", "slack"]
22+
* ["😂", ":joy:", "github"]
23+
*/
24+
publicfunctiontestEmojify(string$expected,string$string, ?string$catalog =null):void
25+
{
26+
$extension =newEmojiExtension();
27+
if ($catalog){
28+
$this->assertSame($expected,$extension->emojify($string,$catalog));
29+
}else {
30+
$this->assertSame($expected,$extension->emojify($string));
31+
}
32+
}
33+
}

‎src/Symfony/Bridge/Twig/composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"symfony/asset":"^6.4|^7.0",
2828
"symfony/asset-mapper":"^6.4|^7.0",
2929
"symfony/dependency-injection":"^6.4|^7.0",
30+
"symfony/emoji":"^7.1",
3031
"symfony/finder":"^6.4|^7.0",
3132
"symfony/form":"^6.4|^7.0",
3233
"symfony/html-sanitizer":"^6.4|^7.0",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp