Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Alex Makdessi:
Diving into Symfony's DependencyInjection - Part 1: First steps with the container
Oct 10, 2018 @ 11:53:34

Alex Makdessi has a post on his Medium.com site kicking off a series of posts taking a deeper look into the Symfony DependencyInjection component. In this first part of the series he takes some of the "first steps" with the container.

this article, we’re going to dive into Symfony’s dependency injection component. We will use it from scratch, out of the Symfony framework, with the minimum of external dependencies. You can code along with me while reading this article, each steps will be detailed so you can easily follow.

He starts off the tutorial by creating a new project and including the DependencyInjection (DI) component via Composer (as well as symfony/var-dumper for debugging). He then starts in on the code showing how to make a ContainerBuilder instance to hold the object instance for reuse. With the container created, we now need something to use it. He creates a basic piece of functionality that works similar to the "voters" included with Symfony's security component to determine if a user has a certain role. He first creates this as a stand-alone tool but then refactors it so that the access manager and post voter objects are pulled from the dependency injection container rather than made manually.

tagged: symfony depdendencyinjection part1 series firststeps voter tutorial

Link: https://medium.com/manomano-tech/diving-into-symfonys-dependencyinjection-part-1-first-steps-with-the-container-2fad0593c052