Skip to content

Commit 6b1b244

Browse files
committed
Add filter alias for Strings::concat
1 parent eb71cdd commit 6b1b244

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ The following checks that `$value` is a non-empty string.
224224
\TraderInteractive\Filter\Strings::filter($value);
225225
```
226226

227+
#### Strings::concat
228+
Aliased in the filterer as `concat`, this filter concatenates the given $value, $prefix and $suffix and returns the resulting string.
229+
```php
230+
$value = \TraderInteractive\Filter\Strings::concat('middle', 'begining_', '_end');
231+
assert($value === 'begining_middle_end');
232+
```
233+
227234
#### Strings::explode
228235
Aliased in the filterer as `explode`, this filter is essentially a wrapper around the built-in [`explode`](http://www.php.net/explode) method
229236
with the value first in order to work with the `Filterer`. It also defaults to using `,` as a delimiter. For example:

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.1"
38+
"traderinteractive/filter-strings": "^3.2.0"
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
@@ -19,6 +19,7 @@ final class Filterer
1919
'arrayize' => '\\TraderInteractive\\Filter\\Arrays::arrayize',
2020
'bool' => '\\TraderInteractive\\Filter\\Booleans::filter',
2121
'bool-convert' => '\\TraderInteractive\\Filter\\Booleans::convert',
22+
'concat' => '\\TraderInteractive\\Filter\\Strings::concat',
2223
'date' => '\\TraderInteractive\\Filter\\DateTime::filter',
2324
'date-format' => '\\TraderInteractive\\Filter\\DateTime::format',
2425
'email' => '\\TraderInteractive\\Filter\\Email::filter',

tests/FiltererTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,16 @@ public function arrayizeAliasIsCalledProperly()
659659
Filterer::filter(['field' => [['arrayize']]], ['field' => 'a string value'])
660660
);
661661
}
662+
663+
/**
664+
* @tests
665+
* @covers ::filter
666+
*/
667+
public function concatAliasIsCalledProperly()
668+
{
669+
$this->assertSame(
670+
[true, ['field' => '%value%'], null, []],
671+
Filterer::filter(['field' => [['concat', '%', '%']]], ['field' => 'value'])
672+
);
673+
}
662674
}

0 commit comments

Comments
 (0)