@@ -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
204232public 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