Skip to content

Commit

Permalink
Merge pull request #103 from chadicus/master
Browse files Browse the repository at this point in the history
Add UUID Filter
  • Loading branch information
chadicus authored Nov 15, 2024
2 parents 4cb52c7 + 5eb9383 commit a4825b7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,16 @@ $value = \TraderInteractive\Filter\TimeOfDayFilter::filter('12:15:23');
assert($value === '12:15:23');
```

#### UuidFilter::filter
Aliased in the filterer as `uuid`, this will filter a given string values as a valid UUID.

The following ensures the `$value` is a valid UUID v4 formatted string. Disallowing null values, nil UUIDs and UUID version other than v4

```php
$value = \TraderInteractive\Filter\UuidFilter::filter('2c02b87a-97ec-4de0-8c50-6721a29c150f', false, false, [4]);
assert($value === '2c02b87a-97ec-4de0-8c50-6721a29c150f');
```

#### XmlFilter::filter
Aliased in the filter as `xml`, this will ensure the given string value is valid XML, returning the original value.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"traderinteractive/filter-dates": "^4.0",
"traderinteractive/filter-floats": "^4.0",
"traderinteractive/filter-ints": "^4.0",
"traderinteractive/filter-strings": "^4.0"
"traderinteractive/filter-strings": "^4.1"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
Expand Down
2 changes: 2 additions & 0 deletions src/Filterer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use TraderInteractive\Filter\Json;
use TraderInteractive\Filter\PhoneFilter;
use TraderInteractive\Filter\TimeOfDayFilter;
use TraderInteractive\Filter\UuidFilter;
use TraderInteractive\Filter\XmlFilter;

/**
Expand Down Expand Up @@ -54,6 +55,7 @@ final class Filterer implements FiltererInterface
'translate' => '\\TraderInteractive\\Filter\\Strings::translate',
'uint' => '\\TraderInteractive\\Filter\\UnsignedInt::filter',
'url' => '\\TraderInteractive\\Filter\\Url::filter',
'uuid' => UuidFilter::class . '::filter',
'xml' => XmlFilter::class . '::filter',
'xml-extract' => XmlFilter::class . '::extract',
'xml-validate' => XmlFilter::class . '::validate',
Expand Down
18 changes: 17 additions & 1 deletion tests/FiltererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,23 @@ function (int $input, int $fieldOneValue) : int {
null,
[],
],

],
'uuid' => [
'spec' => [
'field' => [['uuid', false, false, [4]]],
],
'input' => [
'field' => '2c02b87a-97ec-4de0-8c50-6721a29c150f',
],
'options' => [],
'result' => [
true,
[
'field' => '2c02b87a-97ec-4de0-8c50-6721a29c150f',
],
null,
[],
],
],
];
}
Expand Down

0 comments on commit a4825b7

Please sign in to comment.