Skip to content

Commit bd2d3af

Browse files
feat(emoji): 😄 😉 Add ServiceProvider, Emoji array store and elegant methods 😅
1 parent 23d7062 commit bd2d3af

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

src/Emoji.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,51 @@
44

55
class Emoji {
66

7+
/**
8+
* Quotes
9+
* @var collection
10+
*/
11+
protected $quotes;
12+
13+
/**
14+
* Get the Quotes from the respective files depending on the Category
15+
* @param string $category
16+
* @return array
17+
*/
18+
private function getEmojis()
19+
{
20+
return require("Emojis/emoji.php");
21+
}
22+
23+
public function findByAlias($emojiName = null)
24+
{
25+
if (is_null($emojiName)) {
26+
throw new \Exception("Please provide the name of the emoji you are looking for");
27+
}
28+
29+
$emoji = strtolower($emojiName);
30+
31+
if (! array_key_exists($emoji, $this->getEmojis())) {
32+
throw new \Exception("Emoji Not Found, Man. Check your spelling and try again");
33+
}
34+
35+
return $this->getEmojis()[$emoji];
36+
}
37+
38+
public function findByName($emojiName = null)
39+
{
40+
$this->findByAlias($emojiName);
41+
}
42+
43+
public function findByUnicode($unicode = null)
44+
{
45+
if (is_null($unicode)) {
46+
throw new \Exception("Please provide a valid UTF-8 Unicode value");
47+
}
48+
49+
$emoji = array_flip($this->getEmojis());
50+
51+
return $emoji[$unicode];
52+
}
53+
754
}

src/EmojiServiceProvider.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Laravel Emoji package.
5+
*
6+
* (c) Prosper Otemuyiwa <prosperotemuyiwa@gmail.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+
namespace Unicodeveloper\Emoji;
13+
14+
use Illuminate\Support\ServiceProvider;
15+
16+
class EmojiServiceProvider extends ServiceProvider {
17+
18+
/*
19+
* Indicates if loading of the provider is deferred.
20+
*
21+
* @var bool
22+
*/
23+
protected $defer = false;
24+
25+
26+
/**
27+
* Register the application services.
28+
*
29+
* @return void
30+
*/
31+
public function register()
32+
{
33+
$this->app->bind('laravel-emoji', function() {
34+
35+
return new Emoji;
36+
37+
});
38+
}
39+
40+
/**
41+
* Get the services provided by the provider
42+
* @return array
43+
*/
44+
public function provides()
45+
{
46+
return ['laravel-emoji'];
47+
}
48+
}

src/Emojis/emoji.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Emoji Emoticons and their Unicode equivalents
8+
|--------------------------------------------------------------------------
9+
| Get the Emoji code from http://www.emoji-cheat-sheet.com/
10+
| and get its equivalent from http://unicode.org/emoji/charts/full-emoji-list.html
11+
|
12+
| Contribute, let's make our laravel apps more emojified
13+
|
14+
*/
15+
16+
"grinning" => "\u{1F600}",
17+
"grin" => "\u{1F601}",
18+
"joy" => "\u{1F602}",
19+
"smiley" => "\u{1F603}",
20+
"smile" => "\u{1F604}",
21+
"sweat_smile" => "\u{1F605}",
22+
"laughing" => "\u{1F606}",
23+
"wink" => "\u{1F609}",
24+
"blush" => "\u{1F60A}",
25+
"yum" => "\u{1F60B}",
26+
"sunglasses" => "\u{1F60E}",
27+
"heart_eyes" => "\u{1F60D}",
28+
"kissing_heart" => "\u{1F618}",
29+
"kissing" => "\u{1F617}",
30+
"kissing_smiling_eyes" => "\u{1F619}",
31+
"kissing_closed_eyes" => "\u{1F61A}",
32+
"relaxed" => "\u{263A}",
33+
34+
];

0 commit comments

Comments
 (0)