DrupalCon Baltimore 2017: Dependency Injection in PHP and Drupal

28:19
539
2
1
0
3
Apr 26, 2017

Dependency Injection sounds like a fancy term for something complicated and advanced. After all, most people didn’t start hearing about this until recently when the PHP world was overtaken by object oriented programming. Dependency Injection sounds intimidating, but it is not. It is simple to understand and once you do, using it in PHP and Drupal is very easy.

In this session, you will learn what Dependency Injection is and how it helps you structure your programs better. You will learn some very basic concepts like constructor injection with analogies and examples and then move on to see how it is done in real life.

Most times, dependency injection is implemented with containers. You will learn how to use some simple dependency injection containers like Pimple in your PHP application. You will also learn how dependency injection is implemented in frameworks like Laravel and Symfony. We will focus on Symfony the most since Drupal uses Symfony’s dependency injection container.

By the end of the session, you will understand:

What is Dependency Injection and how does it help us
Constructor and setter injection
Why do we need Dependency Injection Containers
How to use Dependency Injection in simple PHP applications and frameworks like Laravel
How to use Dependency Injection in Symfony and Drupal 8
How to write YAML files to define services and their dependencies

Hi! I'm Karim Boudjema, the developer and site-builder of this site. I'm currently working as a freelance Drupal developer.

I was wondering how could I giving back to the Drupal community all what it gave to me during the last 10 years, that's how the idea of this site came to me ... (read more)

Hi! I’m Santiago Rico, the web designer and themer of this site.

When Karim proposed me to design and theme this site for the Drupal community, I accepted immediately because the community is the main reason why I love Drupal so much.