Skip to content

Commit

Permalink
Start to simplify environment and add twemoji extension for real use …
Browse files Browse the repository at this point in the history
…case
  • Loading branch information
markhalliwell committed Mar 10, 2021
1 parent 63b164b commit b53d161
Show file tree
Hide file tree
Showing 133 changed files with 4,095 additions and 1,688 deletions.
59 changes: 37 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,55 @@ To install it via [Composer] simply run:
$ composer require unicorn-fail/emoji
```

The `UnicornFail\Emoji\Converter` class provides a simple wrapper for converting emoticons, HTML entities and
The `UnicornFail\Emoji\Emoji` class provides a simple wrapper for converting emoticons, HTML entities and
shortcodes to proper unicode characters (emojis):

```php
use UnicornFail\Emoji\Converter;
use UnicornFail\Emoji\Emojibase\DatasetInterface;
use UnicornFail\Emoji\Emojibase\ShortcodeInterface;

// Default configuration.
$configuration = [
'convertEmoticons' => true,
'exclude' => [
use UnicornFail\Emoji\EmojiConverter;
use UnicornFail\Emoji\Emojibase\EmojibaseDatasetInterface;
use UnicornFail\Emoji\Emojibase\EmojibaseShortcodeInterface;

$defaultConfiguration = [
/** @var array<string, string> (see EmojiConverter::TYPES) */
'convert' => [
EmojiConverter::EMOTICON => EmojiConverter::UNICODE,
EmojiConverter::HTML_ENTITY => EmojiConverter::UNICODE,
EmojiConverter::SHORTCODE => EmojiConverter::UNICODE,
EmojiConverter::UNICODE => EmojiConverter::UNICODE,
],

/** @var array<string, mixed> */
'exclude' => [
/** @var string[] */
'shortcodes' => [],
],
'locale' => 'en',
'native' => null, // auto, true or false depending on locale set.
'presentation' => DatasetInterface::EMOJI,
'preset' => ShortcodeInterface::DEFAULT_PRESETS,
];

$converter = new Converter($configuration);
/** @var string */
'locale' => 'en',

/** @var ?bool */
'native' => null, // Auto (null), becomes true or false depending on locale set.

/** @var int */
'presentation' => EmojibaseDatasetInterface::EMOJI,

/** @var string[] */
'preset' => EmojibaseShortcodeInterface::DEFAULT_PRESETS,
];

// Convert applicable values to unicodes (emojis).
// Convert all applicable values to unicode emojis (default configuration).
$converter = EmojiConverter::create();
echo $converter->convert('We <3 :unicorn: :D!');
// or
echo $converter->convertToUnicode('We <3 :unicorn: :D!');
// We ❤️ 🦄 😀!
// Convert applicable values to HTML entities.
echo $converter->convertToHtml('We <3 :unicorn: :D!');
// Convert all applicable values to HTML entities.
$converter = EmojiConverter::create(['convert' => EmojiConverter::HTML_ENTITY]);
echo $converter->convert('We <3 :unicorn: :D!');
// We \&#x2764; \&#x1F984; \&#x1F600;!
// Convert applicable values to shortcodes.
echo $converter->convertToShortcode('We <3 :unicorn: :D!');
// Convert all applicable values to shortcodes.
$converter = EmojiConverter::create(['convert' => EmojiConverter::SHORTCODE]);
echo $converter->convert('We <3 :unicorn: :D!');
// We :red-heart: :unicorn-face: :grinning-face:!
```
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
],
"require": {
"php": "^7.2.5 || ^8.0",
"ext-json": "*",
"ext-mbstring": "*",
"ext-zlib": "*",
"doctrine/lexer": "^1.2",
Expand Down Expand Up @@ -114,6 +115,7 @@
"@phpcs",
"@phpstan",
"@psalm",
"@putenv XDEBUG_MODE=coverage",
"@phpunit-coverage"
]
},
Expand Down
Loading

0 comments on commit b53d161

Please sign in to comment.