├── .github ├── FUNDING.yml └── dependabot.yml ├── .editorconfig ├── src ├── helpers.php ├── Emoji.php └── EmojiServiceProvider.php ├── config └── emoji.php ├── composer.json └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [overtrue] 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: composer 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "21:00" 8 | open-pull-requests-limit: 10 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = false 10 | 11 | [*.{vue,js,scss}] 12 | charset = utf-8 13 | indent_style = space 14 | indent_size = 2 15 | end_of_line = lf 16 | insert_final_newline = true 17 | trim_trailing_whitespace = true 18 | 19 | [*.md] 20 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | use Emojione\Client; 13 | 14 | if (! function_exists('emoji')) { 15 | /** 16 | * Convert emoji shortname to image. 17 | * 18 | * @param string $shortname 19 | * @return string 20 | */ 21 | function emoji($shortname) 22 | { 23 | return call_user_func([app(Client::class), config('emoji.default_helper_method', 'shortnameToUnicode')], $shortname); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Emoji.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | return [ 13 | // defualt method of 'emoji' function: 14 | // emoji($string); 15 | 'default_helper_method' => 'shortnameToUnicode', 16 | 17 | /* 18 | * Client options 19 | */ 20 | 'options' => [ 21 | // defaults to jsdelivr's free CDN 22 | 'image_path' => null, 23 | 24 | // use sprite image. 25 | 'sprites' => false, 26 | 27 | // available sizes are '32' and '64' 28 | 'sprite_size' => 32, 29 | 30 | // convert ascii smileys? 31 | 'ascii' => false, 32 | 33 | // convert shortcodes? 34 | 'shortcodes' => true, 35 | 36 | // use the unicode char as the alt attribute (makes copy and pasting the resulting text better) 37 | 'unicode_alt' => true, 38 | 39 | // available sizes are '32', '64', and '128' 40 | 'emoji_size' => 64, 41 | 42 | // emoji version 43 | 'emoji_version' => '3.1', 44 | ], 45 | ]; 46 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "overtrue/laravel-emoji", 3 | "description": "An emojione bridge for Laravel.", 4 | "type": "library", 5 | "require": { 6 | "laravel/framework": "^9.0|^10.0|^11.0", 7 | "joypixels/emoji-toolkit": "^6.6" 8 | }, 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "overtrue", 13 | "email": "anzhengchao@gmail.com" 14 | } 15 | ], 16 | "autoload": { 17 | "psr-4": { 18 | "Overtrue\\LaravelEmoji\\": "src" 19 | }, 20 | "files": [ 21 | "src/helpers.php" 22 | ] 23 | }, 24 | "extra": { 25 | "laravel": { 26 | "providers": [ 27 | "Overtrue\\LaravelEmoji\\EmojiServiceProvider" 28 | ], 29 | "aliases": { 30 | "Emoji": "Overtrue\\LaravelEmoji\\Emoji" 31 | } 32 | }, 33 | "hooks": { 34 | "pre-commit": [ 35 | "composer check-style" 36 | ], 37 | "pre-push": [ 38 | "composer check-style" 39 | ] 40 | } 41 | }, 42 | "scripts": { 43 | "post-update-cmd": [ 44 | "cghooks update" 45 | ], 46 | "post-merge": "composer install", 47 | "post-install-cmd": [ 48 | "cghooks add --ignore-lock", 49 | "cghooks update" 50 | ], 51 | "cghooks": "vendor/bin/cghooks", 52 | "check-style": "vendor/bin/pint --test", 53 | "fix-style": "vendor/bin/pint", 54 | "test": "vendor/bin/phpunit" 55 | }, 56 | "scripts-descriptions": { 57 | "test": "Run all tests.", 58 | "check-style": "Run style checks (only dry run - no fixing!).", 59 | "fix-style": "Run style checks and fix violations." 60 | }, 61 | "require-dev": { 62 | "laravel/pint": "*" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/EmojiServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 17 | __DIR__.'/../config/emoji.php' => config_path('emoji.php'), 18 | ], 'laravel-emoji'); 19 | } 20 | 21 | $this->registerBladeDirectiveIfNeeded(); 22 | } 23 | 24 | public function register() 25 | { 26 | $this->mergeConfigFrom(dirname(__DIR__).'/config/emoji.php', 'emoji'); 27 | 28 | $this->app->bind(Client::class, function () { 29 | $client = new Client(new Ruleset()); 30 | 31 | if ($path = \config('emoji.options.image_path')) { 32 | $client->imagePathPNG = $path; 33 | } 34 | 35 | $client->sprites = \config('emoji.options.sprites'); 36 | $client->spriteSize = \config('emoji.options.sprite_size'); 37 | $client->emojiSize = \config('emoji.options.emoji_size'); 38 | $client->emojiVersion = \config('emoji.options.emoji_version'); 39 | $client->unicodeAlt = \config('emoji.options.unicode_alt'); 40 | $client->shortcodes = \config('emoji.options.shortcodes'); 41 | $client->ascii = \config('emoji.options.ascii'); 42 | 43 | return $client; 44 | }); 45 | 46 | $this->app->alias(Client::class, 'emoji'); 47 | } 48 | 49 | public function provides() 50 | { 51 | return [Client::class, 'emoji']; 52 | } 53 | 54 | protected function registerBladeDirectiveIfNeeded() 55 | { 56 | if (class_exists('Illuminate\Support\Facades\Blade')) { 57 | \Illuminate\Support\Facades\Blade::directive('emoji', function ($expression) { 58 | return ""; 59 | }); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Emoji 2 | 3 | :smile: This package assist you in getting started with emoji easily. 4 | 5 | ![Laravel Octane Ready Status](https://img.shields.io/badge/Octance-ready-green?style=flat-square) 6 | ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/overtrue/laravel-emoji?style=flat-square) 7 | ![GitHub License](https://img.shields.io/github/license/overtrue/laravel-emoji?style=flat-square) 8 | ![Packagist Downloads](https://img.shields.io/packagist/dt/overtrue/laravel-emoji?style=flat-square) 9 | 10 | [![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue) 11 | 12 | ## Installing 13 | 14 | ```shell 15 | $ composer require overtrue/laravel-emoji 16 | ``` 17 | 18 | ## Usage 19 | 20 | ```php 21 | Emoji::toImage(':smile:'); // 😄' 22 | Emoji::toShort('😄'); // :smile: 23 | Emoji::shortnameToUnicode(':smile:'); // 😄 24 | 25 | // using helper 26 | // default transform shorname to unicode, you can change it in config file. 27 | emoji(':smile:'); // 😄 28 | 29 | // access emoji services, return \Emojione\Client instance. 30 | app('emoji'); 31 | // or 32 | app(\Emojione\Client::class); 33 | ``` 34 | 35 | ### Configurations 36 | 37 | ```shell 38 | // config 39 | $ php artisan vendor:publish --provider="Overtrue\\LaravelEmoji\\EmojiServiceProvider" --tag=config 40 | ``` 41 | 42 | ## :heart: Sponsor me 43 | 44 | [![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue) 45 | 46 | 如果你喜欢我的项目并想支持它,[点击这里 :heart:](https://github.com/sponsors/overtrue) 47 | 48 | 49 | ## Project supported by JetBrains 50 | 51 | Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects. 52 | 53 | [![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/overtrue) 54 | 55 | ## PHP 扩展包开发 56 | 57 | > 想知道如何从零开始构建 PHP 扩展包? 58 | > 59 | > 请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package) 60 | 61 | ## License 62 | 63 | MIT 64 | --------------------------------------------------------------------------------