Skip to content

Commit 684b702

Browse files
authored
Merge pull request #82 from chadicus/master
Add alias for Strings::translate
2 parents e13dead + 776918e commit 684b702

4 files changed

Lines changed: 15 additions & 1 deletion

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ $value = \TraderInteractive\Filter\Strings::stripTags('A string with <p>tags</p>
247247
assert($value === 'a string with tags');
248248
```
249249

250+
#### Strings::translate
251+
Aliased in the filterer as `translate`, this filter will accept a string value and return its translated value found in the given $valueMap.
252+
```php
253+
$value = \TraderInteractive\Filter\Strings::tranlsate('bar', ['foo' => 'translated to bar', 'bar' => 'translated to foo']);
254+
assert($value === 'translated to foo');
255+
```
256+
250257
#### Url::filter
251258
Aliased in the filterer as `url`, this filter verifies that the argument is a URL string according to
252259
[RFC2396](http://www.faqs.org/rfcs/rfc2396). The second parameter can be set to `true` to allow

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"traderinteractive/filter-dates": "^3.0",
3636
"traderinteractive/filter-floats": "^3.0",
3737
"traderinteractive/filter-ints": "^3.0",
38-
"traderinteractive/filter-strings": "^3.2.0"
38+
"traderinteractive/filter-strings": "^3.3"
3939
},
4040
"require-dev": {
4141
"php-coveralls/php-coveralls": "^1.0",

src/Filterer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ final class Filterer
3434
'string' => '\\TraderInteractive\\Filter\\Strings::filter',
3535
'strip-tags' => '\\TraderInteractive\\Filter\\Strings::stripTags',
3636
'timezone' => '\\TraderInteractive\\Filter\\DateTimeZone::filter',
37+
'translate' => '\\TraderInteractive\\Filter\\Strings::translate',
3738
'uint' => '\\TraderInteractive\\Filter\\UnsignedInt::filter',
3839
'url' => '\\TraderInteractive\\Filter\\Url::filter',
3940
];

tests/FiltererTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ public function provideValidFilterData() : array
210210
'options' => [],
211211
'result' => [true, ['field' => '%value%'], null, []],
212212
],
213+
'translate alias' => [
214+
'spec' => ['field' => [['translate', ['active' => 'A', 'inactive' => 'I']]]],
215+
'input' => ['field' => 'inactive'],
216+
'options' => [],
217+
'result' => [true, ['field' => 'I'], null, []],
218+
],
213219
];
214220
}
215221

0 commit comments

Comments
 (0)