I’m working on a controller that handles logins for a Web app. These logins will come from multiple clients but will all contain the same data. However, depending on the client, this data will be interpreted into common entities for our webapp differently.
For instance, we have a user code that gets sent in, and in one case we may use the first four digits of the code, and in another case 12 digits of the code to map to a field on a User entity.
Instead of handling this all in the controller and having big nasty if blocks of logic, I would like to use a pattern to handle how this information gets ingested into our application.
What are your opinions?
It’s hard to understand exactly what the problem is without knowing more about how your program currently works. However, if I understand correctly, you don’t really need a ‘pattern’ as such.
I would simply refactor the “big nasty blocks of if logic” into a class that handles deciding what to do with the data. Perhaps something like this (PHP code):
You can then use it like this:
This will keep all of the conditional logic out of the controller and allow you to reuse the code in other controllers.