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 - PHP Tutorial
From the course: PHP: Design Patterns
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Introducing the Action-Domain-Response pattern1m 43s
-
(Locked)
Exploring a use case for the Action-Domain-Response pattern1m 34s
-
(Locked)
The Action-Domain-Response pattern in action1m 11s
-
(Locked)
Challenge: Apply the Action-Domain-Response pattern48s
-
(Locked)
Solution: Apply the Action-Domain-Response pattern2m
-
(Locked)
-
-
-
-
-