I struggling with following problem:
- User send message via form
- Request is passed to controller
(In controller) - App checks if user is logged
- App checks if user has permission to send messages
- App prepares (filter/validate) data send from app
- Controller pass data to
Service
layer
(In service) - Service inserts data to database
- Service returns result to controller
(In controller) - App creates
View Model
and send result to user's browser
Problem
Users have status (it's kind of role but more detailed) and I have to check if user's status allows to specific actions.
For example:
I have "status-checkers":
- MessageChecker - class to check if user with provided status may send message
- LimitChecker - class to check if user with provided status didn't exceeded message limit
- SomethingElseChecker
I'm looking for a way (design pattern) to easily add/remove checker without modifying controller or service.
Let's say I have configuration array with these active checkers:
checker.config.php
return [
'Namespace\Checker\MessageChecker',
'Namespace\Checker\LimitChecker',
'Namespace\Checker\FooChecker'
];
What next? Should I pass it to controller and check it on this level? Or to service and check it on this layer? What design pattern will be suitable for my problem?
Aucun commentaire:
Enregistrer un commentaire