Skip to content

Commit

Permalink
Refactor DateTimeSelect
Browse files Browse the repository at this point in the history
Signed-off-by: ramchale <[email protected]>
  • Loading branch information
ramchale committed Dec 13, 2024
1 parent cc21318 commit f1795cf
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 211 deletions.
18 changes: 18 additions & 0 deletions docs/book/v3/migration/v2-to-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ RuntimeException are no longer thrown when the filter receives an array with the
All invalid values passed to the filter, invalid calendar dates, will now return the original value.
Validators should be used to ensure the input has been filtered as expected, and to enforce any additional constraints.

#### `DateTimeSelect`

The following methods have been removed:

- `setOptions`
- `getOptions`
- `setNullOnAllEmpty`
- `isNullOnAllEmpty`
- `setNullOnEmpty`
- `isNullOnEmpty`

The constructor now only accepts an associative array of [documented options](../standard-filters.md#datetimeselect).

RuntimeException are no longer thrown when the filter receives an array with the incorrect number of elements.

All invalid values passed to the filter, invalid calendar dates or times, will now return the original value.
Validators should be used to ensure the input has been filtered as expected, and to enforce any additional constraints.

#### `DenyList`

The following methods have been removed:
Expand Down
24 changes: 24 additions & 0 deletions docs/book/v3/standard-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,30 @@ $filter = new \Laminas\Filter\DateTimeFormatter([
echo $filter->filter('2024-01-01'); // => 2024-01-01T00:00:00+01:00
```

## DateTimeSelect

`Laminas\Filter\DateTimeSelect` allows you to filter second, minute, hour, day, month, and year values into a string of format `Y-m-d H:i:s`.
If not in the input array, second will default to 0.

### Supported Options

The following options are supported for `Laminas\Filter\DateTimeSelect`:

- `null_on_empty` => This defaults to `false`.
If set to `true`, the filter will return `null` if minute, hour, day, month, or year are empty.
- `null_on_all_empty` => This defaults to `false`.
If set to `true`, the filter will return `null` if minute, hour, day, month, and year are empty.

### Basic Usage

```php
$filter = new Laminas\Filter\DateTimeSelect();

print $filter->filter(['second' => '1', 'month' => '2', 'hour' => '3', 'day' => '4', 'month' => '5', 'year' => '2012']);
````

This will return '2012-05-04 03:02:01'.

## DecompressArchive

This filter accepts an archive in the form of a file path, a PHP uploaded file array or a PSR-7 uploaded file and de-compresses the file to a configured target directory returning the location where the files are expanded.
Expand Down
14 changes: 0 additions & 14 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/AbstractDateDropdown.php">
<DeprecatedClass>
<code><![CDATA[AbstractFilter]]></code>
</DeprecatedClass>
<PossiblyUnusedMethod>
<code><![CDATA[setNullOnAllEmpty]]></code>
<code><![CDATA[setNullOnEmpty]]></code>
</PossiblyUnusedMethod>
</file>
<file src="src/AbstractFilter.php">
<DocblockTypeContradiction>
<code><![CDATA[gettype($options)]]></code>
Expand All @@ -31,11 +22,6 @@
<code><![CDATA[is_object($options)]]></code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/DateTimeSelect.php">
<MixedReturnStatement>
<code><![CDATA[$value]]></code>
</MixedReturnStatement>
</file>
<file src="src/Dir.php">
<DeprecatedClass>
<code><![CDATA[AbstractFilter]]></code>
Expand Down
147 changes: 0 additions & 147 deletions src/AbstractDateDropdown.php

This file was deleted.

Loading

0 comments on commit f1795cf

Please sign in to comment.