V
V
Vadim Milevsky2018-01-10 17:51:08
MySQL
Vadim Milevsky, 2018-01-10 17:51:08

Code location when working with Doctrine?

The essence of the question is that I am currently working on a relatively small project, and there all requests for the doctrine lie directly in the controllers, which is not solid. But there are not only uploads, there are updates and deletions, so it doesn’t work to put everything on the same repositories, standard from the doctrine.
Tell me, maybe there is a proven structure for the location of such code so as not to store it only in controllers, because if you dig, you can easily find a bunch of duplication in console commands, which is not good

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2018-01-10
@3gsxarakiri

Work with a DB goes in repositories.
That is, the hierarchy is as follows:
- the simplest operations with the database are done through the ORM in Entity.
- complex queries, grouping data from several queries, query builders - in the repository
- the rest of the business logic code that works with data received from the database - in the helper.
At the same time, it must be remembered that in addition to working with the database, the rest of the business logic must also be removed from the controller. To service/helper.
To check the correct separation of the business logic, you need to make a console command that does the same thing as the controller action. If the command does not duplicate the code from the action (with the exception of the helper call), then the division was successful

O
Oleg Lysenko, 2018-01-10
@oleglysenko

Usually, business logic is taken out in a separate layer. Write service classes where you put your business logic. Where they will lie and how to be called - this, in fact, is your business already. And then inject the services themselves into the controllers and call the methods you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question