Skip to content

Commit

Permalink
Merge pull request #3 from unicorn-fail/ast-environment
Browse files Browse the repository at this point in the history
Refactor AST/Environment
  • Loading branch information
markhalliwell authored Mar 16, 2021
2 parents 8c53008 + c2e4fb1 commit 3903cc8
Show file tree
Hide file tree
Showing 153 changed files with 8,177 additions and 3,318 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ jobs:

- run: composer update -o --no-progress

- run: vendor/bin/psalm --no-progress --output-format=github --shepherd
- run: vendor/bin/psalm --no-progress --output-format=github --shepherd || true
61 changes: 38 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,56 @@ 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!');
// We :red-heart: :unicorn-face: :grinning-face:!
// Convert all applicable values to shortcodes.
$converter = EmojiConverter::create(['convert' => EmojiConverter::SHORTCODE]);
echo $converter->convert('We <3 :unicorn: :D!');
// We :heart: :unicorn: :grinning:!
```
Please note that only UTF-8 and ASCII encodings are supported. If your content uses a different encoding please
Expand Down
19 changes: 11 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,25 @@
"repositories": [
{
"type": "vcs",
"url": "https://github.com/markcarver/phpunit-pretty-print.git"
"url": "https://github.com/unicorn-fail/configuration.git"
}
],
"require": {
"php": "^7.2.5 || ^8.0",
"ext-json": "*",
"ext-mbstring": "*",
"ext-zlib": "*",
"dflydev/dot-access-data": "^2.0",
"doctrine/lexer": "^1.2",
"symfony/options-resolver": "^5.1",
"league/configuration": "dev-latest",
"psr/event-dispatcher": "^1.0",
"symfony/polyfill-php80": "^1.15"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12.42",
"phpunit/phpunit": "^8.5.8",
"scrutinizer/ocular": "^1.5",
"sempro/phpunit-pretty-print": "dev-patch-1#d90a03400a038d8bb3b9413cfcce83d1274c09ec",
"sempro/phpunit-pretty-print": "^1.4",
"squizlabs/php_codesniffer": "^3.5",
"unleashedtech/php-coding-standard": "^2.5",
"vimeo/psalm": "^3.14"
Expand Down Expand Up @@ -97,12 +98,13 @@
]
},
"scripts": {
"emojibase": "npm install && npm run build && php ./scripts/build.php",
"phpcs": "phpcs",
"phpstan": "phpstan analyse",
"build": "npm install && npm run build && php ./scripts/build.php",
"fix": "vendor/bin/phpcbf",
"phpcs": "vendor/bin/phpcs",
"phpstan": "vendor/bin/phpstan analyse",
"phpunit": "./scripts/phpunit --no-coverage --colors=always",
"phpunit-coverage": "./scripts/phpunit --colors=always",
"psalm": "psalm --config=psalm.xml --output-format=phpstorm --show-info=true --stats --threads=4",
"psalm": "vendor/bin/psalm --config=psalm.xml --output-format=phpstorm --show-info=true --stats --threads=4",
"test": [
"@phpcs",
"@phpstan",
Expand All @@ -113,6 +115,7 @@
"@phpcs",
"@phpstan",
"@psalm",
"@putenv XDEBUG_MODE=coverage",
"@phpunit-coverage"
]
},
Expand Down
Loading

0 comments on commit 3903cc8

Please sign in to comment.