From the course: PHP: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Apply the Action-Domain-Response pattern

Solution: Apply the Action-Domain-Response pattern - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

Solution: Apply the Action-Domain-Response pattern

- All right, so let's dive into this one. First, our index.php file has changed quite a bit. We have a ton of includes, which is a great time to talk about autoloading. If you're not using an autoloader, you should really check into it, and see what you can do for your classes. It makes life easier. I've done it manually here to show you the pain. Don't suffer it yourself. Anyway, just like before, we have a switch statement to make sure we get the right action we're expecting, but this time around, instead of getting the action directly, we're using a factory pattern withe the request as an input. This is key because without that we don't know what action the user needs. So let's look at that factory. It does exactly as we'd expect. It uses a switch statement to figure out which action to return, instantiates a new one, and then returns it. One useful thing to note here, if we get an action that we don't recognize, we return a default action, just so the system has something to…

Contents