I come from the Java / Grails background and cannot find a definitive answer on the Internet about where the service logic for the CakePHP application should be stored. “Services,” I'm talking about classes that are usually created through dependency injection to conduct business logic on domain objects. They should be able to query any domain object and make changes in response to the action of the controller.
CakePHP's "Component" class currently seems to be the closest to this behavior. I can load the component into any controller and execute its methods as needed. However, I read in several places that components should never access the database, and that this will lead to some cool performance results.
I also looked at CakePHP's Behavior class, and it doesn't seem to fit the ticket at all. It seems well-equipped for organizing domain objects in setting up the data structure, but this is not the logic that the service will execute. Also, in order to import any model definition into Behavior, I would have to edit the model definition itself to allow access, which is very inconvenient.
So, I ask this question: where should the service logic be stored? Of course, not a controller, since it should contain only minimal logic to process the request and send a response.
source share