Skip to content

Commit ca1f488

Browse files
committed
Merge branch 'release/0.9.2'
2 parents d5d2445 + be1c98b commit ca1f488

File tree

9 files changed

+279
-519
lines changed

9 files changed

+279
-519
lines changed

.version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"strategy": "semver",
33
"major": 0,
44
"minor": 9,
5-
"patch": 1,
5+
"patch": 2,
66
"build": 0
77
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"ext-json": "*",
1616
"neuron-php/application": "0.8.*",
1717
"neuron-php/routing": "0.8.*",
18+
"neuron-php/dto": "^0.0.7",
1819
"league/commonmark": "^2.6",
1920
"neuron-php/cli": "0.8.*",
2021
"robmorgan/phinx": "^0.16",

examples/config/requests/login.yaml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ request:
66
username:
77
required: true
88
type: string
9-
minLength: 3
10-
maxLength: 20
9+
length:
10+
min: 3
11+
max: 20
1112
password:
1213
required: true
1314
type: string
14-
minLength: 8
15-
maxLength: 50
15+
length:
16+
min: 8
17+
max: 50
1618
age:
1719
type: integer
18-
minimum: 18
19-
maximum: 40
20+
range:
21+
min: 18
22+
max: 40
2023
birthdate:
2124
type: string
2225
format: date
@@ -28,20 +31,24 @@ request:
2831
street:
2932
required: true
3033
type: string
31-
minLength: 3
32-
maxLength: 10
34+
length:
35+
min: 3
36+
max: 10
3337
city:
3438
required: true
3539
type: string
36-
minLength: 3
37-
maxLength: 20
40+
length:
41+
min: 3
42+
max: 20
3843
state:
3944
required: true
4045
type: string
41-
minLength: 2
42-
maxLength: 2
46+
length:
47+
min: 2
48+
max: 2
4349
zip:
4450
required: true
4551
type: string
46-
minLength: 3
47-
maxLength: 20
52+
length:
53+
min: 3
54+
max: 20

examples/config/requests/test.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ request:
2727
integer:
2828
required: true
2929
type: integer
30-
minValue: 1
31-
maxValue: 100
30+
range:
31+
min: 1
32+
max: 100
3233
ip_address:
3334
required: true
3435
type: ip_address
@@ -45,18 +46,21 @@ request:
4546
subparam1:
4647
required: true
4748
type: string
48-
minLength: 3
49-
maxLength: 20
49+
length:
50+
min: 3
51+
max: 20
5052
subparam2:
5153
required: true
5254
type: string
53-
minLength: 3
54-
maxLength: 20
55+
length:
56+
min: 3
57+
max: 20
5558
string:
5659
required: true
5760
type: string
58-
minLength: 3
59-
maxLength: 20
61+
length:
62+
min: 3
63+
max: 20
6064
time:
6165
required: true
6266
type: time

readme.md

Lines changed: 70 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,52 @@ routes:
187187

188188
### Request Handling
189189

190-
Create request parameter definitions for validation:
190+
Create request DTO definitions for validation. You can define DTOs inline or reference external DTO files:
191+
192+
**Inline DTO Definition:**
191193

192194
```yaml
193195
# config/requests/user_profile.yaml
194-
parameters:
195-
id:
196-
type: integer
196+
request:
197+
method: GET
198+
properties:
199+
id:
200+
type: integer
201+
required: true
202+
range:
203+
min: 1
204+
```
205+
206+
**Referenced DTO:**
207+
208+
```yaml
209+
# config/requests/user_create.yaml
210+
request:
211+
method: POST
212+
dto: user # References config/Dtos/user.yaml or src/Dtos/user.yaml
213+
```
214+
215+
```yaml
216+
# config/Dtos/user.yaml (or src/Dtos/user.yaml)
217+
dto:
218+
username:
219+
type: string
220+
required: true
221+
length:
222+
min: 3
223+
max: 20
224+
email:
225+
type: email
197226
required: true
198-
min_value: 1
199227
```
200228

201-
Access parameters in controllers:
229+
Access validated data in controllers:
202230

203231
```php
204232
public function profile(Request $request): string
205233
{
206-
$userId = $request->getParam('id')->getValue();
234+
$dto = $request->getDto();
235+
$userId = $dto->id;
207236
// ...
208237
}
209238
```
@@ -448,7 +477,7 @@ class ProductController extends Base
448477
449478
public function details(Request $request): string
450479
{
451-
$id = $request->getParam('id')->getValue();
480+
$id = $request->getRouteParameter('id');
452481
$product = $this->getProduct($id);
453482
454483
if (!$product) {
@@ -470,40 +499,48 @@ class ProductController extends Base
470499
}
471500
```
472501

473-
### Request Parameter Validation
502+
### Request Validation with DTOs
474503

475-
Define parameters in YAML:
504+
Define request DTOs in YAML:
476505

477506
```yaml
478507
# config/requests/product_create.yaml
479-
parameters:
480-
name:
481-
type: string
482-
required: true
483-
min_length: 3
484-
max_length: 100
485-
486-
price:
487-
type: currency
488-
required: true
489-
min_value: 0
490-
491-
category_id:
492-
type: integer
493-
required: true
494-
495-
description:
496-
type: string
497-
required: false
498-
max_length: 1000
508+
request:
509+
method: POST
510+
headers:
511+
Content-Type: application/json
512+
properties:
513+
name:
514+
type: string
515+
required: true
516+
length:
517+
min: 3
518+
max: 100
519+
520+
price:
521+
type: currency
522+
required: true
523+
range:
524+
min: 0
525+
526+
category_id:
527+
type: integer
528+
required: true
529+
530+
description:
531+
type: string
532+
required: false
533+
length:
534+
max: 1000
499535
```
500536

501-
Available parameter types:
537+
Available property types:
502538
- `string`, `integer`, `float`, `boolean`
503539
- `email`, `url`, `uuid`
504-
- `date`, `datetime`
505-
- `currency`, `phone_number`
540+
- `date`, `date_time`, `time`
541+
- `currency`, `us_phone_number`, `intl_phone_number`
506542
- `array`, `object`
543+
- `ip_address`, `ein`, `upc`, `name`, `numeric`
507544

508545
### Error Handling
509546

0 commit comments

Comments
 (0)