Dependency Injection or: How I Learned to Stop Worrying and Love OO-PHP

Submitted by Marc on Wed, 04/25/2018 - 21:01

I spent much of the past 2 days deep in training on Drupal 8 module development. I'm using the fantastic and the articles on Even though I went though the OO-PHP training recently so more of the Drupal 8 stuff makes more sense than before, my head was still reeling from all of the new particles whizzing past.

Now, I feel I understand more of the syntax with classes - things like "namespaces", "extends", and "implements". I am slowly grasping how things are called inside the classes. However, when it comes to things like dependency injection, I'm sort of at a loss. I mean, conceptually I get why you use it - to use less memory and processor time and ultimately speed up your application. I just think it'll take me a little bit of time to wrap my head around the complex syntax and where to put "all the things".

I know - I've only just started this journey. It's going to take some time to get used to the new way of doing things. However, it dawned on me that one of the reasons this whole training is so daunting is that I'm not only learning Drupal 8, but also OO-PHP, Symfony, TWIG and YAML (but let's be honest YAML is really simple). All at the same time! It makes the jump from Drupal 7 to 8 much trickier. I'm looking forward to when I can launch sites on it though - there are some COOL things you can do with D8.

Luckily, I was able to create my first "Hello World" module today and have added a block to the system. It's not much, but, IIRC, that is how I started with Drupal 7 development too. Slow and steady. So, here's hoping things click into place soon. Next up is tacking how I can add a settings form, save configuration data (a whole different world than D7), and then caching data from an external web service call. Whee!

I'll try and post more code snippets when I can. For now, I'm still trying to wrap my head around what I'm even writing!