You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/doctrine-filters.md
+46-28Lines changed: 46 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,10 +56,7 @@ class Book {
56
56
57
57
## Basic Knowledge
58
58
59
-
Filters are services (see the section on [custom filters](../core/filters.md#creating-custom-filters)), and they can be linked
60
-
to a Resource in two ways:
61
-
62
-
1. Through the resource declaration, as the `filters` attribute.
59
+
Filters are services (see the section on [custom filters](../core/filters.md#creating-custom-filters)), the can be linked to an API Platform Operation throuh [parameters](./filters.md):
63
60
64
61
For example, having a filter service declaration in `services.yaml`:
65
62
@@ -72,11 +69,6 @@ services:
72
69
tags: ['api_platform.filter']
73
70
```
74
71
75
-
> [!WARNING]
76
-
> Its discouraged to use a filter with properties in the dependency injection as it may conflict with how
77
-
> `QueryParameter` works. We recommend to use a per-parameter filter or to use the :property placeholder with a defined
78
-
> `filterContext` specifying your strategy for a given set of parameters.
79
-
80
72
We're linking the filter `offer.date_filter` with the resource like this:
81
73
82
74
```php
@@ -93,6 +85,32 @@ class Offer
93
85
}
94
86
```
95
87
88
+
> [!WARNING]
89
+
> Its discouraged to use a filter with properties in the dependency injection as it may conflict with how
90
+
> `QueryParameter` works. We recommend to use a per-parameter filter or to use the :property placeholder with a defined
91
+
> `filterContext` specifying your strategy for a given set of parameters.
92
+
93
+
Since API platform 4.2 we're allowing singleton objects, indeed a filter now acts on a single parameter associated
94
+
with a single scalar value (or a list). You may use the [`:property` placeholder](./filters.md#filtering-multiple-properties-with-property))
95
+
96
+
```php
97
+
<?php
98
+
// api/src/ApiResource/Offer.php
99
+
namespace App\ApiResource;
100
+
101
+
#[GetCollection(
102
+
parameters: [
103
+
'createdAt' => new QueryParameter(
104
+
filter: new DateFilter(),
105
+
),
106
+
],
107
+
)]
108
+
class Offer
109
+
{
110
+
// ...
111
+
}
112
+
```
113
+
96
114
For MongoDB ODM, all the filters are in the namespace `ApiPlatform\Doctrine\Odm\Filter`. The filter
97
115
services all begin with `api_platform.doctrine_mongodb.odm`.
98
116
@@ -102,7 +120,7 @@ services all begin with `api_platform.doctrine_mongodb.odm`.
102
120
> The SearchFilter is a multi-type filter that may have inconsistencies (eg: you can search a partial date with LIKE)
103
121
> we recommend to use type-specific filters such as `PartialSearchFilter` or `DateFilter` instead.
104
122
105
-
### Built-in new Search Filters since API Platform >= 4.2
123
+
### Built-in Search Filters since API Platform >= 4.2
106
124
107
125
To add some search filters, choose over this new list:
108
126
@@ -132,7 +150,7 @@ The search filter supports `exact`, `partial`, `start`, `end`, and `word_start`
132
150
- `word_start`strategy uses `LIKE text% OR LIKE % text%` to search for fields that contain words starting with `text`.
133
151
134
152
Prepend the letter `i` to the filter if you want it to be case insensitive. For example `ipartial` or `iexact`. Note that
135
-
this will use the `LOWER` function and **will** impact performance [if there is no proper index](performance.md#search-filter).
153
+
this will use the `LOWER` function and will impact performance [as described in the performance documentation](./performance#search-filter).
136
154
137
155
Case insensitivity may already be enforced at the database level depending on the [collation](https://en.wikipedia.org/wiki/Collation)
138
156
used. If you are using MySQL, note that the commonly used `utf8_unicode_ci` collation (and its sibling `utf8mb4_unicode_ci`)
@@ -180,7 +198,7 @@ Syntax: `?property=value`
180
198
181
199
The value can take any [IRI(Internationalized Resource Identifier)](https://en.wikipedia.org/wiki/Internationalized_Resource_Identifier).
182
200
183
-
Like other [new search filters](#built-in-new-search-filters-api-platform--42) it can be used on the ApiResource attribute
201
+
This filter can be used on the ApiResource attribute
184
202
or in the operation attribute, for e.g., the `#GetCollection()` attribute:
185
203
186
204
```php
@@ -210,7 +228,7 @@ Syntax: `?property=value`
210
228
211
229
The value can take any scalar value or array of values.
212
230
213
-
Like other [new search filters](#built-in-new-search-filters-api-platform--42) it can be used on the ApiResource attribute
231
+
This filter can be used on the ApiResource attribute
214
232
or in the operation attribute, for e.g., the `#GetCollection()` attribute:
215
233
216
234
```php
@@ -240,7 +258,7 @@ Syntax: `?property=value`
240
258
241
259
The value can take any scalar value or array of values.
242
260
243
-
Like other [new search filters](#built-in-new-search-filters-api-platform--42) it can be used on the ApiResource attribute
261
+
This filter can be used on the ApiResource attribute
244
262
or in the operation attribute, for e.g., the `#GetCollection()` attribute:
245
263
246
264
```php
@@ -275,7 +293,7 @@ Syntax: `?property=value`
275
293
276
294
The value can take any scalar value or array of values.
277
295
278
-
Like other [new search filters](#built-in-new-search-filters-api-platform--42) it can be used on the ApiResource attribute
296
+
This filter can be used on the ApiResource attribute
279
297
or in the operation attribute, for e.g., the `#GetCollection()` attribute:
280
298
281
299
```php
@@ -388,7 +406,7 @@ class Offer
388
406
```
389
407
390
408
> [!TIP]
391
-
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [here](#introduction).
409
+
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [in the Introduction section](#introduction).
392
410
393
411
### Date Filter using the ApiFilter Attribute Syntax (not recommended)
394
412
@@ -505,7 +523,7 @@ class Offer
505
523
```
506
524
507
525
> [!TIP]
508
-
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [here](#introduction).
526
+
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [in the Introduction section](#introduction).
509
527
510
528
## Boolean Filter
511
529
@@ -539,7 +557,7 @@ class Offer
539
557
```
540
558
541
559
> [!TIP]
542
-
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [here](#introduction).
560
+
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [in the Introduction section](#introduction).
543
561
544
562
### Result using the Boolean Filter
545
563
@@ -579,7 +597,7 @@ class Offer
579
597
```
580
598
581
599
> [!TIP]
582
-
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [here](#introduction).
600
+
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [in the Introduction section](#introduction).
583
601
584
602
### Result using the Numeric Filter
585
603
@@ -619,7 +637,7 @@ class Offer
619
637
```
620
638
621
639
> [!TIP]
622
-
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [here](#introduction).
640
+
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [in the Introduction section](#introduction).
623
641
624
642
### Result using the Range Filter
625
643
@@ -662,7 +680,7 @@ class Offer
662
680
```
663
681
664
682
> [!TIP]
665
-
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [here](#introduction).
683
+
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [in the Introduction section](#introduction).
666
684
667
685
### Result using the Exists Filter
668
686
@@ -743,7 +761,7 @@ class Offer
743
761
After that, you can use it with the following query: `/offers?order[name]=desc&order[id]=asc`.
744
762
745
763
> [!TIP]
746
-
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [here](#introduction).
764
+
> For other syntaxes, for e.g., if you want to new syntax with the ApiResource attribute take a look [in the Introduction section](#introduction).
747
765
748
766
### Result using the Order Filter
749
767
@@ -755,14 +773,14 @@ order with the following query: `/offers?order[name]=desc&order[id]=asc`.
755
773
By default, whenever the query does not specify the direction explicitly (e.g.: `/offers?order[name]&order[id]`), filters
756
774
will not be applied unless you configure a default order direction to use:
For other sort strategies (about `null` values), please refer to the [Handling Null Values with the Order Filter section](#comparing-with-null-values-using-order-filter).
768
786
@@ -1397,8 +1415,8 @@ This allows delegating validation to API Platform, respecting the [SOLID Princip
1397
1415
>
1398
1416
> You can see how this works directly in our code components:
1399
1417
>
1400
-
> - The `ParameterValidatorProvider` for **Symfony** can be found [here](https://github.com/api-platform/core/blob/c9692b509d5b641104addbadb349b9bcab83e251/src/Symfony/Validator/State/ParameterValidatorProvider.php).
1401
-
> - The `ParameterValidatorProvider` for **Laravel** is located [here](https://github.com/api-platform/core/blob/c9692b509d5b641104addbadb349b9bcab83e251/src/Laravel/State/ParameterValidatorProvider.php).
1418
+
> - The `ParameterValidatorProvider` for **Symfony** can be found [in the Symfony ParameterValidatorProvider.php file](https://github.com/api-platform/core/blob/c9692b509d5b641104addbadb349b9bcab83e251/src/Symfony/Validator/State/ParameterValidatorProvider.php).
1419
+
> - The `ParameterValidatorProvider` for **Laravel** is located [in the Laravel ParameterValidatorProvider.php file](https://github.com/api-platform/core/blob/c9692b509d5b641104addbadb349b9bcab83e251/src/Laravel/State/ParameterValidatorProvider.php).
1402
1420
>
1403
1421
> Additionally, we filter out empty values within our `ParameterExtension` classes. For instance, the **Doctrine ORM**
1404
1422
> `ParameterExtension` [handles this filtering here](https://github.com/api-platform/core/blob/c9692b509d5b641104addbadb349b9bcab83e251/src/Doctrine/Orm/Extension/ParameterExtension.php#L51C13-L53C14).
@@ -1668,8 +1686,8 @@ This allows delegating validation to API Platform, respecting the [SOLID Princip
1668
1686
>
1669
1687
> You can see how this works directly in our code components:
1670
1688
>
1671
-
> - The `ParameterValidatorProvider` for **Symfony** can be found [here](https://github.com/api-platform/core/blob/c9692b509d5b641104addbadb349b9bcab83e251/src/Symfony/Validator/State/ParameterValidatorProvider.php).
1672
-
> - The `ParameterValidatorProvider` for **Laravel** is located [here](https://github.com/api-platform/core/blob/c9692b509d5b641104addbadb349b9bcab83e251/src/Laravel/State/ParameterValidatorProvider.php).
1689
+
> - The `ParameterValidatorProvider` for **Symfony** can be found [in the Symfony ParameterValidatorProvider.php file](https://github.com/api-platform/core/blob/c9692b509d5b641104addbadb349b9bcab83e251/src/Symfony/Validator/State/ParameterValidatorProvider.php).
1690
+
> - The `ParameterValidatorProvider` for **Laravel** is located [in the Laravel ParameterValidatorProvider.php file](https://github.com/api-platform/core/blob/c9692b509d5b641104addbadb349b9bcab83e251/src/Laravel/State/ParameterValidatorProvider.php).
1673
1691
>
1674
1692
> Additionally, we filter out empty values within our `ParameterExtension` classes. For instance, the **Doctrine ODM**
1675
1693
> `ParameterExtension` [handles this filtering here](https://github.com/api-platform/core/blob/c9692b509d5b641104addbadb349b9bcab83e251/src/Doctrine/Odm/Extension/ParameterExtension.php#L50-L52).
Copy file name to clipboardExpand all lines: core/dto.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,9 @@ In API Platform, [the general design considerations](design.md) recommended patt
10
10
11
11
This reference covers three implementation strategies:
12
12
13
-
* [State Options: Linking a DTO Resource to an Entity for automated CRUD operations.](#1-the-dto-resource-state-options)
14
-
* [Automated Mapped Inputs: Using input DTOs with stateOptions for automated Write operations.](#2-automated-mapped-inputs-outputs)
15
-
* [Custom Business Logic: Using input DTOs with custom State Processors for specific business actions.](#3-custom-business-logic-custom-processor)
13
+
-[State Options: Linking a DTO Resource to an Entity for automated CRUD operations.](#1-the-dto-resource-state-options)
14
+
-[Automated Mapped Inputs: Using input DTOs with stateOptions for automated Write operations.](#2-automated-mapped-inputs-and-outputs)
15
+
-[Custom Business Logic: Using input DTOs with custom State Processors for specific business actions.](#3-custom-business-logic-custom-processor)
16
16
17
17
## 1. The DTO Resource (State Options)
18
18
@@ -116,9 +116,9 @@ Automated mapping relies on two internal classes: `ApiPlatform\State\Provider\Ob
116
116
117
117
These classes act as decorators around the standard Provider/Processor chain. They are activated when:
118
118
119
-
* The Object Mapper component is available.
120
-
* `stateOptions` are configured with an `entityClass` (or `documentClass` for ODM).
121
-
* The Resource (and Entity for writes) classes have the `#[Map]` attribute.
119
+
- The Object Mapper component is available.
120
+
-`stateOptions` are configured with an `entityClass` (or `documentClass` for ODM).
121
+
- The Resource (and Entity for writes) classes have the `#[Map]` attribute.
122
122
123
123
#### How it works internally
124
124
@@ -130,7 +130,7 @@ The `ObjectMapperProvider` delegates fetching the data to the underlying Doctrin
130
130
131
131
The `ObjectMapperProcessor` receives the deserialized Input DTO. It uses `$objectMapper->map($inputDto, $entityClass)` to transform the input into an Entity instance. It then delegates to the underlying Doctrine processor (to persist the Entity). Finally, it maps the persisted Entity back to the Output DTO Resource.
132
132
133
-
## 2. Automated Mapped Inputs & Outputs
133
+
## 2. Automated Mapped Inputs and Outputs
134
134
135
135
Ideally, your read and write models should differ. You might want to expose less data in a collection view (Output DTO) or enforce strict validation during creation/updates (Input DTOs).
Copy file name to clipboardExpand all lines: core/elasticsearch-filters.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ class Book {
52
52
}
53
53
```
54
54
55
-
**Further Reading**
55
+
## Further Reading
56
56
57
57
- Consult the documentation on [Per-Parameter Filters (Recommended Method)](../core/filters.md#2-per-parameter-filters-recommended).
58
58
- If you are working with a legacy codebase, you can refer to the [documentation for the old syntax (deprecated)](../core/filters.md#1-legacy-filters-searchfilter-etc---not-recommended).
Copy file name to clipboardExpand all lines: core/graphql.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -680,7 +680,7 @@ Your custom queries will be available like this:
680
680
681
681
## Mutations
682
682
683
-
If you don't know what mutations are yet, the documentation about them is [here](https://graphql.org/learn/queries/#mutations).
683
+
If you don't know what mutations are yet, the documentation about them is [in the GraphQL documentation for mutations](https://graphql.org/learn/queries/#mutations).
0 commit comments