Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shimabox/pemojine

Pemojine is a library for handling Emoji in PHP.
https://github.com/shimabox/pemojine

emoji

Last synced: 22 days ago
JSON representation

Pemojine is a library for handling Emoji in PHP.

Awesome Lists containing this project

README

        


pemojine-logo

# Pemojine

Pemojine is a library for handling Emoji in PHP.

[![License](https://poser.pugx.org/shimabox/pemojine/license)](https://packagist.org/packages/shimabox/pemojine)
[![Build Status](https://travis-ci.org/shimabox/pemojine.svg?branch=master)](https://travis-ci.org/shimabox/pemojine)
[![Maintainability](https://api.codeclimate.com/v1/badges/ab677ae3d8ae014ad6ed/maintainability)](https://codeclimate.com/github/shimabox/pemojine/maintainability)
[![Coverage Status](https://coveralls.io/repos/github/shimabox/pemojine/badge.svg?branch=master)](https://coveralls.io/github/shimabox/pemojine?branch=master)
[![Latest Stable Version](https://poser.pugx.org/shimabox/pemojine/v/stable)](https://packagist.org/packages/shimabox/pemojine)
[![Latest Unstable Version](https://poser.pugx.org/shimabox/pemojine/v/unstable)](https://packagist.org/packages/shimabox/pemojine)

![demo](https://github.com/shimabox/assets/raw/master/pemojine/demo.gif)

This library is getting data from here.

- [Full Emoji List, v13.1](https://unicode.org/emoji/charts/full-emoji-list.html "Full Emoji List, v13.1")
- [Full Emoji Modifier Sequences, v13.1](https://unicode.org/emoji/charts/full-emoji-modifiers.html "Full Emoji Modifier Sequences, v13.1")
- [emoji-toolkit/emoji.json at master · joypixels/emoji-toolkit](https://github.com/joypixels/emoji-toolkit/blob/master/emoji.json "emoji-toolkit/emoji.json at master · joypixels/emoji-toolkit")

## Attention

- Support for php5.5-7.3

## Architecture

pemojine-architecture

- Treat one Emoji as a group.
- MediumGroup bundle Groups.
- BigGroup bundle MediumGroups.
- Vendor bundle BigGroups.
- @see [Full Emoji List, v13.1](https://unicode.org/emoji/charts/full-emoji-list.html "Full Emoji List, v13.1")

## Features

- You can output it for each vendor (Apple, Google, etc...).
- Outputable for each group.
- BigGroups, MediumGroups, Groups.
- Randomly output Emoji.
- Create sentences containing Emoji.
- The group structure can be easily customized.

## Demo

- Todo

## Installation

Via Composer

```
$ composer require shimabox/pemojine
```

Develop

```
$ git clone https://github.com/shimabox/pemojine
$ cd pemojine
$ composer install
```

## Usage

```php
getVendorName(); // => Google

/*
|----------------------------------------------------------------------
| Get all BigGroups.
|----------------------------------------------------------------------
*/
$allBigGroups = $pemojine->getAllBigGroups();

// $allBigGroups is an array with a big group name in the key and an object(BigGroup) in the value.
foreach ($allBigGroups as $bigGroupName => $bigGroup) {
echo 'BigGroupName::' . $bigGroupName/* or $bigGroup->getName() */;
foreach ($bigGroup as $mediumGroupName => $mediumGroup) {
echo 'MediumGroupName::' . $mediumGroupName/* or $mediumGroup->getName() */;
foreach ($mediumGroup as $groupName => $group) {
// Output shortName.
echo 'Group::' . $groupName/* or $group->getName(), $group->getShortName() */;
// Output Emoji.
echo $group->output();
// Output HTML reference character. e.g) '😀', '🇯🇵'
echo htmlspecialchars($group->outputHtml(), ENT_QUOTES, 'UTF-8');
// Get unicode. e.g.) 'U+1F600', 'U+1F1EF U+1F1F5'
echo $group->getUnicode();
// Get unicode with removed blank. e.g.) 'U+1F600', 'U+1F1EFU+1F1F5'
echo $group->getUnicodeWithRemovedBlank();
// Get UTF8 string. e.g.) '\u{1F600}', '\u{1F1EF} \u{1F1F5}'
echo $group->getUtf8String();
// Get UTF8 string with removed blank. e.g.) '\u{1F600}', '\u{1F1EF}\u{1F1F5}'
echo $group->getUtf8StringWithRemovedBlank();
// Get aliases of shortName
$alias = implode(' ', $group->getAliasesOfName()/* or $group->getAliasesOfShortName() */);
echo htmlspecialchars($alias, ENT_QUOTES, 'UTF-8');
}
}
}

/*
|----------------------------------------------------------------------
| When selecting randomly from Big Groups.
|----------------------------------------------------------------------
*/
// Select a BigGroup at random
$randomBigGroup = $pemojine->randomFromBigGroup();

echo $randomBigGroup->getName(); // Randomly chosen BigGroupName.

// When acquiring a random group from narrowed down.
$groupOfBig = $randomBigGroup->getGroupAtRandom();
echo $groupOfBig->getName();
$alias = implode(' ', $groupOfBig->getAliasesOfName());
echo htmlspecialchars($alias, ENT_QUOTES, 'UTF-8');
echo $groupOfBig->output();
echo htmlspecialchars($groupOfBig->outputHtml(), ENT_QUOTES, 'UTF-8');
echo $groupOfBig->getUnicode();
echo $groupOfBig->getUnicodeWithRemovedBlank();
echo $groupOfBig->getUtf8String();
echo $groupOfBig->getUtf8StringWithRemovedBlank();

/*
|----------------------------------------------------------------------
| When selecting 'animal-mammal' in Medium Groups.
|----------------------------------------------------------------------
*/
// Select 'animal-mammal'.
$selectedMediumGroup = $pemojine->selectMediumGroup('animal-mammal');

echo $selectedMediumGroup->getVendorName(); // => 'Google'

echo $selectedMediumGroup->getName(); // => 'animal-mammal'

// $selectedMediumGroup is an iterator with a group name in the key and an object(Group) in the value.
foreach ($selectedMediumGroup/* or $selectedMediumGroup->getChildren() */ as $groupName => $group) {
echo 'Group::' . $groupName;
echo $group->output();
echo htmlspecialchars($group->outputHtml(), ENT_QUOTES, 'UTF-8');
echo $group->getUnicode();
echo $group->getUnicodeWithRemovedBlank();
echo $group->getUtf8String();
echo $group->getUtf8StringWithRemovedBlank();
$alias = implode(' ', $group->getAliasesOfName());
echo htmlspecialchars($alias, ENT_QUOTES, 'UTF-8');
}

// When acquiring a random group from narrowed down.
$groupOfM = $selectedMediumGroup->getGroupAtRandom();
echo $groupOfM->getName()/* or $groupOfM->getShortName() */;
$alias = implode(' ', $groupOfM->getAliasesOfName()/* or $groupOfM->getAliasesOfShortName() */);
echo htmlspecialchars($alias, ENT_QUOTES, 'UTF-8');
echo $groupOfM->output();
echo htmlspecialchars($groupOfM->outputHtml(), ENT_QUOTES, 'UTF-8');
echo $groupOfM->getUnicode();
echo $groupOfM->getUnicodeWithRemovedBlank();
echo $groupOfM->getUtf8String();
echo $groupOfM->getUtf8StringWithRemovedBlank();

// In the case of Medium Group, you can find a Big Group of parents.
$parent = $pemojine->selectMediumGroup('animal-mammal')->findParentGroup(); // => Parent BigGroup
assert($parent->getName() === 'Animals & Nature'); // => true

// The following are the same instances.
$a = $pemojine->selectBigGroup('Animals & Nature')->selectMediumGroup('animal-mammal');
$b = $pemojine->selectMediumGroup('animal-mammal');
assert($a === $b); // => true

// Exists?
assert($pemojine->hasMediumGroup('animal-bird') === true);
assert($pemojine->hasMediumGroup('piyo') === false);

/*
|----------------------------------------------------------------------
| Create sentences including Emoji.
|----------------------------------------------------------------------
*/
// Get an Outputter instance.
$outputter = $pemojine->getOutputter();

// Other ways to get instances.
/*
// Create an EmojiTable instance of Apple.
$emojiTable = new \SMB\Pemojine\Structure\Vendor\Apple\EmojiTable();
// Create an Outputter instance.
$outputter = new \SMB\Pemojine\Outputter\Outputter($emojiTable);
*/

// Create a Sentence instance.
$sentence = new Sentence($outputter);

// Sentence 1
$output_1 = $sentence->create('Hello U+1F1EFU+1F1F5 \u{1F601}:grin:|beaming face with smiling eyes|!!');
assert('Hello 🇯🇵 😁😁😁!!' === $output_1);
echo $output_1;

// Sentence 2
$output_2 = $sentence->create('foo ::heart:: :bar:cinema:baz:');
assert('foo :❤: :bar🎦baz:' === $output_2);
echo $output_2;

// Sentence 3
$output_3 = $sentence->create('foo ||grinning face with big eyes|| |bar|face with tears of joy|baz|');
assert('foo |😃| |bar😂baz|' === $output_3);
echo $output_3;
```

## Customize

### How to add a new Emoji group

Create three files below.

- Files that implements `SMB\Pemojine\Structure\Interfaces\Configurable`.
- Files that implements `SMB\Pemojine\Structure\Interfaces\Gettable`.
- Files that implements `SMB\Pemojine\Structure\Interfaces\EmojiTable\Gettable`.

@see [example/Custom](https://github.com/shimabox/pemojine/tree/master/example/Custom "pemojine/example/Custom at master · shimabox/pemojine")

## Examples (dev only)

#### Basic

- [example/getAll.php](https://github.com/shimabox/pemojine/blob/master/example/getAll.php "pemojine/getAll.php at master · shimabox/pemojine")
- `$ php example/getAll.php`
- [example/selectAtRandom.php](https://github.com/shimabox/pemojine/blob/master/example/selectAtRandom.php "pemojine/selectAtRandom.php at master · shimabox/pemojine")
- `$ php example/selectAtRandom.php`
- [example/selectGroup.php](https://github.com/shimabox/pemojine/blob/master/example/selectGroup.php "pemojine/selectGroup.php at master · shimabox/pemojine")
- `$ php example/selectGroup.php`
- [example/outputter.php](https://github.com/shimabox/pemojine/blob/master/example/outputter.php "pemojine/outputter.php at master · shimabox/pemojine")
- `$ php example/outputter.php`

#### Helper

- [example/helper_converter.php](https://github.com/shimabox/pemojine/blob/master/example/helper_converter.php "pemojine/helper_converter.php at master · shimabox/pemojine")
- `$ php example/helper_converter.php`
- [example/helper_emoji.php](https://github.com/shimabox/pemojine/blob/master/example/helper_emoji.php "pemojine/helper_emoji.php at master · shimabox/pemojine")
- `$ php example/helper_emoji.php`
- [example/helper_emojiCounter.php](https://github.com/shimabox/pemojine/blob/master/example/helper_emojiCounter.php "pemojine/helper_emojiCounter.php at master · shimabox/pemojine")
- `$ php example/helper_emojiCounter.php`
- [example/helper_sentence.php](https://github.com/shimabox/pemojine/blob/master/example/helper_sentence.php "pemojine/helper_sentence.php at master · shimabox/pemojine")
- `$ php example/helper_sentence.php`

#### Custom

- [example/Custom/example.php](https://github.com/shimabox/pemojine/blob/master/example/Custom/example.php "pemojine/example.php at master · shimabox/pemojine")
- `$ php example/Custom/example.php`

## Regenerate data (dev only)

```
$ php scraping/src/generator.php
```

Scrape the data here.
(The result is cached for 1 hour in `scraping/cache/full-emoji-list`, `scraping/cache/full-emoji-modifiers`)

- [Full Emoji List, v13.1](https://unicode.org/emoji/charts/full-emoji-list.html "Full Emoji List, v13.1")
- [Full Emoji Modifier Sequences, v13.1](https://unicode.org/emoji/charts/full-emoji-modifiers.html "Full Emoji Modifier Sequences, v13.1")
- [emoji-toolkit/emoji.json at master · joypixels/emoji-toolkit](https://github.com/joypixels/emoji-toolkit/blob/master/emoji.json "emoji-toolkit/emoji.json at master · joypixels/emoji-toolkit")

`scraping/output/Config`, `scraping/output/Structure` Since files are output below, please place them under `src/Config`, `src/Structure` respectively.

### Shell for sync.

- For Mac(Linux).
```
$ sh scraping/sync.sh
```

- For Windows.
```
$ cd scraping/
$ win_sync.bat
```

## Test

```
$ composer test # or vendor/bin/phpunit
```

- Coverage
```
$ composer coverage # or vendor/bin/phpunit --coverage-text --coverage-html ./report/
```

## TODO

- Make a demo site.
- Regular expressions that make up sentences with Emoji are rough.
- [pemojine/Sentence.php at master · shimabox/pemojine](https://github.com/shimabox/pemojine/blob/master/src/Helper/Sentence.php "pemojine/Sentence.php at master · shimabox/pemojine").
- I tried to cope with nesting.
- But it does not correspond to complex nesting.
- Emoji mapping(array) is too rich, so I need to think about this.
- For `Vendor\JoyPixels` I feel correct to combine with [emoji-toolkit/lib/php at master · joypixels/emoji-toolkit](https://github.com/joypixels/emoji-toolkit/tree/master/lib/php "emoji-toolkit/lib/php at master · joypixels/emoji-toolkit").
- Confirmation on actual machine.

## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.