Check your version
This collection covers a topic in which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of , but we consider it archived.
Now it's time to level up with services. These special PHP objects are the backbone of what makes Symfony unique and fast. It's also the reason that organizing your code into reusable chunks is so easy. But beyond that, once you understand how services and the service container work, you'll be absolutely unstoppable inside of Symfony. This series, from our friends at KnpUniversity covers:
- What is a service?
- List, fetch, and use existing services
- Create your own custom services
- Register your service
- Check out the (mystical) dumped container
- Configuration Parameters
- Dependency Injection Tags
If you haven't already, check out Joyful Development with Symfony and Symfony 3 Fundamentals: Bundles, Configuration and Environments to get caught up with Symfony 3 fundamentals.
In this lesson, we'll explore what problems a services architecture can solve. You'll learn how services can unlock a bunch of powerful features for you in Symfony 3.
New to Symfony 3 or need a brush up on Symfony concepts? Check out these series first and then head back here to dive into Services and the Container.
Note: To set up the project and code along, see the instructions in start/README.md.
In this lesson, we'll move code out of the Controller and into a new class. You'll learn how to create this new service class and refactor the code that you took out of the Controller to work in this new context.
In this lesson, you'll learn about the dependency injection workflow and refactor our code to inject the dependency.
In this lesson you'll learn how use type-hinting to make your code more portable—and readable, too.
In this lesson, you'll learn how to register your service in the container so that you can can access it in your class.
In this lesson you'll inject cache service, applying what we've already learned about dependency injection and type-hinting as we refactor the code in our evolving app.
In this lesson, you'll learn how to extend Twig and create a Twig extension service to use in our Symfony 3 app.
In this lesson, we'll add tags to our services YAML file so that Twig knows about our new Twig extension. We'll discuss the reason behind tags and refactor our service with our new understanding of dependency injection tags!
In this lesson you'll learn what happens when you set
autowire to true when you register your service.