-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kyle Millloy
authored and
Kyle Millloy
committed
Jun 17, 2022
1 parent
4f3c892
commit 0ee8d82
Showing
8 changed files
with
242 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Emoji | ||
|
||
Adds support for inserting and converting emojis into unicode in PHP. Uses enums and so requires PHP8.1 or higher. | ||
|
||
## Installation | ||
|
||
`composer require itsnubix/emoji` | ||
|
||
## Usage | ||
|
||
```php | ||
use Emoji\Emoji; | ||
use Emoji\SkinTone; | ||
|
||
// Globally set skin tone for all applicable emojis | ||
Emoji::setDefaultSkinTone(SkinTone::medium); | ||
|
||
// Various methods for spitting out a unicode emoji | ||
Emoji::get('grinning_face')->toString(); // returns 😀 | ||
(string) Emoji::grinning_face(); // returns 😀 | ||
echo Emoji::grinningFace(); // returns 😀 | ||
|
||
// Overwrite the default skin tone on the fly | ||
Emoji::get('waving_hand', SkinTone::light)->toString(); // returns 👋🏻 | ||
Emoji::wavingHand()->light()->toString(); // returns 👋🏻 | ||
Emoji::wavingHand()->skinTone('light')->toString(); // returns 👋🏻 | ||
|
||
// Also supports dynamic skin tone selection with a callback | ||
$user = new User(['preferred_skin_tone' => SkinTone::light]) | ||
Emoji::wavingHand() | ||
->skinTone(fn() => $user->preferred_skin_tone) | ||
->toString(); | ||
|
||
// You may also reset | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use Emoji\Emoji; | ||
use Emoji\Enums\SkinTone; | ||
|
||
it('can resolve a skin tone from a string', function () { | ||
foreach (SkinTone::names() as $name) { | ||
expect(SkinTone::tryToResolve($name))->not->toBeNull(); | ||
} | ||
}); | ||
|
||
it('can resolve a skin tone from a callable', function () { | ||
foreach (SkinTone::names() as $name) { | ||
expect(SkinTone::tryToResolve(fn () => $name))->not->toBeNull(); | ||
} | ||
}); | ||
|
||
it('throws if an invalid tone is supplied to the resolve function', function () { | ||
SkinTone::resolve('invalid-tone'); | ||
})->throws(ValueError::class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters