From eec720738143f089d9db9a957d52948d3b806872 Mon Sep 17 00:00:00 2001 From: soyuka Date: Wed, 7 Nov 2018 14:39:42 +0100 Subject: [PATCH] Document input/output resource attribute --- core/dto.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/core/dto.md b/core/dto.md index 95650143315..3c762b42e54 100644 --- a/core/dto.md +++ b/core/dto.md @@ -2,6 +2,8 @@ ## How to Use a DTO for Writing +!> The following isn't recommended anymore, please use [Input/Output](specify-an-input-and-or-output-class) instead + Sometimes it's easier to use a DTO than an Entity when performing simple operation. For example, the application should be able to send an email when someone has lost its password. @@ -126,6 +128,8 @@ services: ## How to Use a DTO for Reading +!> The following isn't recommended anymore, please use [Input/Output](specify-an-input-and-or-output-class) instead + Sometimes, you need to retrieve data not related to an entity. For example, the application can send the [list of supported locales](https://github.com/symfony/demo/blob/master/config/services.yaml#L6) @@ -350,3 +354,68 @@ use Swagger\Annotations as SWG; */ public function __invoke() ``` + +### Specify an Input and/or Output Class + +For a given resource class, you may want to have a different representation of this class as input (write) or output (read). +To do so, a resource can take an input and/or an output class: + +```php +name = $data->name; + $output->id = 1; + + return $output; + } + + public function remove($data) + { + // TODO: implement removal + return null; + } +} +```