Thu 26-09-2024 by benjamin
I started this week implementing a service container into my project. This acts as a place to store and retrieve instances of singletons and other dependencies we need. I learnt a bit more about dependency injection: the container I built can call an action or build a class even with dependencies, it does this by using a ReflectionMethod to either retrieve or build any decencies it has been told how to build. I also learnt about providers, classes that tell the container how to build certain objects. My MySQL model uses prepared statements but when starting to look at security I learnt the power this provides in that I don't have to worry about SQL injection! I then learnt how to protect my site from js injection by sanitising/validating my data. I read an article on SOLID design principles. I put this into practice by separating my MySql repository from my controller class using an interface. Learnt how useful this was by designing another interface to implement json storage. Because of the decoupling I had done when looking at SOLID, I can use either my MySql or json repositories, so long as they implement my interface. Picked up a few other things: Refactored my notification 'status' to instead be an enum, I had not used enums before but this made a big difference to the readability of my Notifier class Started using phpstan bleeding edge which drew attention to my miss use of global variables