And now it's time to build out the actual api for Mabel.
Looking at the documentation for Slim 4, I'm going to allow Slim 4 to instantiate my controller classes for me. This allows me to write the controllers in a manner that's similar to what I've done in the past.
Namely, I'm going to create controller classes that contain methods that are related. In other words, I'm going to create three controllers: Authorization.php, Accounts.php and Anonymous.php.
Then I'm going to add routing to docroot/index.php that explicitly links each URI path to a specific class and method that should be invoked.
Somehow, Slim 4 magically passes the Request and Response objects and the request arguments to each method in each controller.
I'm also magically able to have the Container object passed into the constructors of the controllers and that's how I'll get the dependencies I'll be using in the controller. I don't really understand yet how any of this magic happens (which I'm never comfortable with) but I suppose that's not important right now.
There's something called auto-wiring that's being utilized, or at least it's an option, because I'm using php-di as my container. I don't understand what that is or why you'd use it. The php-di documentation really talks it up, but I prefer not to use something I don't yet understand.
No comments:
Post a Comment