Skip to content

Commit fef4966

Browse files
authored
Merge pull request #105 from chadicus/v3.x
AGI-1181: Add 'strip-emoji' filter
2 parents 296dc12 + d491a73 commit fef4966

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
@@ -605,6 +605,13 @@ $value = \TraderInteractive\Filter\Strings::explode('abc,def,ghi');
605605
assert($value === ['abc', 'def', 'ghi']);
606606
```
607607

608+
#### Strings::stripEmoji
609+
Aliased in the filterer as `strip-emoji`, this filter removes emoji characters from a given string optionally replacing them with the given replacement string
610+
```php
611+
$value = \TraderInteractive\Filter\Strings::stripEmoji('this is ridiculous🙄', '!');
612+
assert($value === 'this is ridiculous!');
613+
```
614+
608615
#### Strings::stripTags
609616
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
610617
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": "^3.1",
3737
"traderinteractive/filter-floats": "^3.0",
3838
"traderinteractive/filter-ints": "^3.0",
39-
"traderinteractive/filter-strings": "^3.6"
39+
"traderinteractive/filter-strings": "^3.7"
4040
},
4141
"require-dev": {
4242
"phpunit/phpunit": "^6.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;
@@ -47,6 +48,7 @@ final class Filterer implements FiltererInterface
4748
'phone' => PhoneFilter::class . '::filter',
4849
'redact' => '\\TraderInteractive\\Filter\\Strings::redact',
4950
'string' => '\\TraderInteractive\\Filter\\Strings::filter',
51+
'strip-emoji' => Strings::class . '::stripEmoji',
5052
'strip-tags' => '\\TraderInteractive\\Filter\\Strings::stripTags',
5153
'time-of-day' => TimeOfDayFilter::class . '::filter',
5254
'timezone' => '\\TraderInteractive\\Filter\\DateTimeZone::filter',

tests/FiltererTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,25 @@ function (int $input, int $fieldOneValue) : int {
549549
[],
550550
],
551551
],
552+
'strip-emoji' => [
553+
'spec' => [
554+
'field' => [['strip-emoji']],
555+
],
556+
'input' => [
557+
'field' => 'This 💩 text contains 😞 multiple emoji 🍔 characters 🍚. As well as an alphanumeric '
558+
. 'supplement 🆗 and flag 🚩',
559+
],
560+
'options' => [],
561+
'result' => [
562+
true,
563+
[
564+
'field' => 'This text contains multiple emoji characters . As well as an alphanumeric '
565+
. 'supplement and flag ',
566+
],
567+
null,
568+
[],
569+
],
570+
],
552571
];
553572
}
554573

0 commit comments

Comments
 (0)