🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 4 Min Lesezeit
0

Creating focused domain applications. A Symfony approach (Returning the result)

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




Introduction



This is the last article of this series. In the previous article we created an application service which used the UserEntityBuilder service to create the entity. Then, the doctrine entity manager (which is an infrastructure service) was used to persist and flush the entity.

Now, it's time to return a result to the presentation layer.




I would like to remember that we have considered the doctrine entities as a domain entities throughout all the articles in the series. I understand that this is not entirely correct and that it would be better to separate the domain entities from the doctrine entities but, for simplicity, I will finish this article using the doctrine entities as domain entities



I am preparing a new article where I will show how i have structured a full Symfony application and there you will see that the domain entities are completely decoupled from doctrine.






Creating an output DTO and an output builder



Before returning the result to the presentation layer, we need to create a DTO to represent the data we want to return. Let's imagine that we only want to return the email, firstName, lastName and dob parameters. Our output DTO would look like this:




CODE
readonly class UserOutputDto {

public function __construct(
public string $email,
public string $firstName,
public string $lastName,
public string $dob,
){}
}






Now that the output DTO is ready, it's time to create a service to build the output from an entity. This service will be part of our domain since we decide what information will be part of the output DTO.




CODE
class UserOutputDTOBuilder {

public function build(User $user): UserOutputDto
{
return new UserOutputDto(
$user->getEmail(),
$user->getFirstName(),
$user->getLastName(),
$user->getDob()
);
}
}






The output builder is pretty simple, it creates a UserOutputDto passing to the constructor the parameters from the entity values.




This output builder could be part of the application or presentation layer since it does not contain any logic but I will keep it in the domain as I did with the UserEntityBuilder.

Remember that the UserEntityBuilder did contain some extra logic:




  • Generate the token

  • Generate the current timestamp







Returning the data



Having the output DTO ready, it's time to direct it towards the presentation layer. In our case, what elements make up the presentation layer?. Taking into account that we are going to generate a Symfony JsonResponse and return it as an HTTP response, the controller would be the element which would represent our presentation layer. Let's return to it.




CODE
class ApiController extends AbstractController
{
#[Route('/api/entity', name: 'api_v1_post_entity', methods: ['POST'])]
public function saveAction(Request $request, DataProcessor $dataProcessor, UserCreator $userCreator): JsonResponse
{
$userInputDto = $dataProcessor->processData($request->getContent(), UserInputDTO::class);
$userOutputDto = $userCreator->createUser($userInputDto);
return $this->json($userInputDto);
}
}







As part of the presentation layer, the symfony controller uses its infrastructure part (the AbstractController json function) to generate a JsonResponse from the output DTO data ready to be returned within a HTTP response.

As you can see, the symfony controller also uses other application services (DataProcessor and UserCreator) to perform the API call process.






Conclusion



In this final article of the series, we explored the process of returning data to the presentation layer in a Symfony application. We began by creating an output Data Transfer Object (DTO) to encapsulate the user data we wanted to return, specifically the email, first name, last name, and date of birth. We then developed a UserOutputDTOBuilder service to construct this DTO from the user entity, emphasizing the importance of defining what information is included in the output.

Finally, we demonstrated how the Symfony controller acts as the presentation layer, utilizing the JsonResponse functionality to return the DTO data as an HTTP response.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Creating focused domain applications. A Symfony approach (Returning the result)

Thematisch verwandte Begriffe: Creating, focused, domain, applications · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...