Skip to content

Commit aaec022

Browse files
committed
Add alias for Arrays::arrayize
1 parent 39dad67 commit aaec022

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ The following does a strict check for `$value` against the 3 accepted values.
156156
\TraderInteractive\Filter\Arrays::in($value, ['a', 'b', 'c']);
157157
```
158158

159+
#### Arrays::arrayize
160+
Aliased in the filterer as `arrayize`, this filter returns this original input if it is an array, otherwise returns input wrapped in an array. If the original input is null, an empty array is returned.
161+
```php
162+
$value = \TraderInteractive\Filter\Arrays::arrayize('a string value');
163+
assert($value === ['a string value']);
164+
```
165+
159166
#### Arrays::filter
160167
Aliased in the filterer as `array`, this filter verifies that the argument is an array and checks the length of the array against bounds. The
161168
default bounds are 1+, so an empty array fails by default.

src/Filterer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ final class Filterer
1616
*/
1717
const DEFAULT_FILTER_ALIASES = [
1818
'array' => '\\TraderInteractive\\Filter\\Arrays::filter',
19+
'arrayize' => '\\TraderInteractive\\Filter\\Arrays::arrayize',
1920
'bool' => '\\TraderInteractive\\Filter\\Booleans::filter',
2021
'bool-convert' => '\\TraderInteractive\\Filter\\Booleans::convert',
2122
'date' => '\\TraderInteractive\\Filter\\DateTime::filter',

tests/FiltererTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,4 +647,16 @@ public function ofArrayUnknown()
647647
$this->assertSame($expected, $e->getMessage());
648648
}
649649
}
650+
651+
/**
652+
* @tests
653+
* @covers ::filter
654+
*/
655+
public function arrayizeAliasIsCalledProperly()
656+
{
657+
$this->assertSame(
658+
[true, ['field' => ['a string value']], null, []],
659+
Filterer::filter(['field' => [['arrayize']]], ['field' => 'a string value'])
660+
);
661+
}
650662
}

0 commit comments

Comments
 (0)