Skip to content

Commit c2149d0

Browse files
refactor(doctrine): reference date filters constants from interface (#2057)
1 parent 8640a7f commit c2149d0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

core/filters.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -664,10 +664,10 @@ Four behaviors are available at the property level of the filter:
664664
| Description | Strategy to set |
665665
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------- |
666666
| Use the default behavior of the DBMS | `null` |
667-
| Exclude items | `ApiPlatform\Doctrine\Orm\Filter\DateFilter::EXCLUDE_NULL` (`exclude_null`) |
668-
| Consider items as oldest | `ApiPlatform\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE` (`include_null_before`) |
669-
| Consider items as youngest | `ApiPlatform\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_AFTER` (`include_null_after`) |
670-
| Always include items | `ApiPlatform\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE_AND_AFTER` (`include_null_before_and_after`) |
667+
| Exclude items | `ApiPlatform\Doctrine\Common\Filter\DateFilterInterface::EXCLUDE_NULL` (`exclude_null`) |
668+
| Consider items as oldest | `ApiPlatform\Doctrine\Common\Filter\DateFilterInterface::INCLUDE_NULL_BEFORE` (`include_null_before`) |
669+
| Consider items as youngest | `ApiPlatform\Doctrine\Common\Filter\DateFilterInterface::INCLUDE_NULL_AFTER` (`include_null_after`) |
670+
| Always include items | `ApiPlatform\Doctrine\Common\Filter\DateFilterInterface::INCLUDE_NULL_BEFORE_AND_AFTER` (`include_null_before_and_after`) |
671671

672672
For instance, exclude entries with a property value of `null` with the following service definition:
673673

@@ -678,12 +678,13 @@ For instance, exclude entries with a property value of `null` with the following
678678
// api/src/Entity/Offer.php
679679
namespace App\Entity;
680680
681+
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
681682
use ApiPlatform\Metadata\ApiFilter;
682683
use ApiPlatform\Metadata\ApiResource;
683684
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
684685
685686
#[ApiResource]
686-
#[ApiFilter(DateFilter::class, properties: ['dateProperty' => DateFilter::EXCLUDE_NULL])]
687+
#[ApiFilter(DateFilter::class, properties: ['dateProperty' => DateFilterInterface::EXCLUDE_NULL])]
687688
class Offer
688689
{
689690
// ...
@@ -1970,6 +1971,7 @@ For example, let's define three data filters (`DateFilter`, `SearchFilter` and `
19701971
// api/src/Entity/DummyCar.php
19711972
namespace App\Entity;
19721973
1974+
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
19731975
use ApiPlatform\Metadata\ApiFilter;
19741976
use ApiPlatform\Metadata\ApiResource;
19751977
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
@@ -1981,7 +1983,7 @@ use Doctrine\ORM\Mapping as ORM;
19811983
19821984
#[ApiResource]
19831985
#[ApiFilter(BooleanFilter::class)]
1984-
#[ApiFilter(DateFilter::class, strategy: DateFilter::EXCLUDE_NULL)]
1986+
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
19851987
#[ApiFilter(SearchFilter::class, properties: ['colors.prop' => 'ipartial', 'name' => 'partial'])]
19861988
#[ApiFilter(PropertyFilter::class, arguments: ['parameterName' => 'foobar'])]
19871989
#[ApiFilter(GroupFilter::class, arguments: ['parameterName' => 'foobargroups'])]
@@ -1998,10 +2000,10 @@ The `BooleanFilter` is applied to every `Boolean` property of the class. Indeed,
19982000
#[ApiFilter(BooleanFilter::class)]
19992001
```
20002002

2001-
The `DateFilter` given here will be applied to every `Date` property of the `DummyCar` class with the `DateFilter::EXCLUDE_NULL` strategy:
2003+
The `DateFilter` given here will be applied to every `Date` property of the `DummyCar` class with the `DateFilterInterface::EXCLUDE_NULL` strategy:
20022004

20032005
```php
2004-
#[ApiFilter(DateFilter::class, strategy: DateFilter::EXCLUDE_NULL)]
2006+
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
20052007
```
20062008

20072009
The `SearchFilter` here adds properties. The result is the exact same as the example with attributes on properties:

0 commit comments

Comments
 (0)