clean-code-php icon indicating copy to clipboard operation
clean-code-php copied to clipboard

Database Interface Layer concrete example

Open hokrc01 opened this issue 6 years ago • 1 comments

Does anyone have a or know of a concrete example of php code that would reflect "Clean Architecture" page 166 figure 17.1. I simply can wrap my head around it?

the attached code represents examples of what I have written so far, but I know this will not work for anything but a SQL database. In my example My use case is simple, I am trying to have a use log into the system. Please ignore my namespace names as I am trying to rework my code from a homemade "MVC" framework. Finally the view component was not included because it is trivial, it send a json string.

Thanks ken

Login Code.zip

hokrc01 avatar Dec 05 '18 18:12 hokrc01

You have a lot of problems in the code.

  • Many principles described in this project are not followed.
  • Validation rules are more appropriately move from the controller on a separate layer.
  • Do not forget about the principles of a thin controller and a thick model.
  • Your model is similar to ActiveRecord, which is anti-pattern and contrary to the principles of DDD.

I recommend to look at Doctrine ORM. And I recommend not to invent your own, but to take a ready-made frameworks, for example, a Symfony. In frameworks, much of what you are doing is already implemented. The frameworks teach programming culture and instill best practices, although some of them are controversial.

peter-gribanov avatar Dec 06 '18 08:12 peter-gribanov