Skip to content

Commit e83286d

Browse files
authored
Merge pull request #106 from chadicus/strip-emoji
AGI-1181: Add 'strip-emoji' filter
2 parents a4825b7 + 74995e9 commit e83286d

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,13 @@ $value = \TraderInteractive\Filter\Strings::explode('abc,def,ghi');
619619
assert($value === ['abc', 'def', 'ghi']);
620620
```
621621

622+
#### Strings::stripEmoji
623+
Aliased in the filterer as `strip-emoji`, this filter removes emoji characters from a given string optionally replacing them with the given replacement string
624+
```php
625+
$value = \TraderInteractive\Filter\Strings::stripEmoji('this is ridiculous🙄', '!');
626+
assert($value === 'this is ridiculous!');
627+
```
628+
622629
#### Strings::stripTags
623630
Aliased in the filterer as `strip-tags`, this filter is essentially a wrapper around the built-in [`strip_tags`](http://php.net/manual/en/function.strip-tags.php) function. However, unlike the
624631
native function the stripTags method will return null when given a null value.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"traderinteractive/filter-dates": "^4.0",
3737
"traderinteractive/filter-floats": "^4.0",
3838
"traderinteractive/filter-ints": "^4.0",
39-
"traderinteractive/filter-strings": "^4.1"
39+
"traderinteractive/filter-strings": "^4.2"
4040
},
4141
"require-dev": {
4242
"phpunit/phpunit": "^9.0",

src/Filterer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use TraderInteractive\Filter\Arrays;
1010
use TraderInteractive\Filter\Json;
1111
use TraderInteractive\Filter\PhoneFilter;
12+
use TraderInteractive\Filter\Strings;
1213
use TraderInteractive\Filter\TimeOfDayFilter;
1314
use TraderInteractive\Filter\UuidFilter;
1415
use TraderInteractive\Filter\XmlFilter;
@@ -49,6 +50,7 @@ final class Filterer implements FiltererInterface
4950
'phone' => PhoneFilter::class . '::filter',
5051
'redact' => '\\TraderInteractive\\Filter\\Strings::redact',
5152
'string' => '\\TraderInteractive\\Filter\\Strings::filter',
53+
'strip-emoji' => Strings::class . '::stripEmoji',
5254
'strip-tags' => '\\TraderInteractive\\Filter\\Strings::stripTags',
5355
'time-of-day' => TimeOfDayFilter::class . '::filter',
5456
'timezone' => '\\TraderInteractive\\Filter\\DateTimeZone::filter',

tests/FiltererTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,25 @@ function (int $input, int $fieldOneValue) : int {
566566
[],
567567
],
568568
],
569+
'strip-emoji' => [
570+
'spec' => [
571+
'field' => [['strip-emoji']],
572+
],
573+
'input' => [
574+
'field' => 'This 💩 text contains 😞 multiple emoji 🍔 characters 🍚. As well as an alphanumeric '
575+
. 'supplement 🆗 and flag 🚩',
576+
],
577+
'options' => [],
578+
'result' => [
579+
true,
580+
[
581+
'field' => 'This text contains multiple emoji characters . As well as an alphanumeric '
582+
. 'supplement and flag ',
583+
],
584+
null,
585+
[],
586+
],
587+
],
569588
];
570589
}
571590

0 commit comments

Comments
 (0)