From the course: Symfony 6 Essential Training

Symfony components

- [Instructor] You have almost certainly used a website or app that is powered by Symfony Components. And it's pretty likely, you've used or are using Symfony components in your PHP code base whether you realize it or not. Symfony Components are small pieces of the Symfony framework that can be used individually. Your project doesn't need to be a symfony project to leverage them. In fact, many well-known projects are leveraging Symfony components. Generally, Symfony components are solving problems that are pretty common. Using Symfony components allows you to focus on the business logic of your app and leverage a library to handle the less exciting components. There are over 200 Symfony Components. They're generally grouped by their purpose. We are going to focus on a few common components and the problems they can solve for you. Let's start with a pretty pedestrian component, Yaml. I want to start with Yaml because it's easy to understand, has very defined functionality, and to me is a great example of a Symfony component. Each component has a page like this. It gives a description of what it does, some helpful links, how to install, and what open source projects are using it. Clicking on read documentation, we get to a beautiful docs page. The nav on the left side breaks down what, why, and both simple and advanced usages. This specific component solves the problem of dealing with Yaml files in PHP. While you could certainly write an implementation to do this, it's useful to have a package that already solves the problem for you. Jumping to the source code for this package, it's also worth noting that it has robust test coverage. I'm pretty sure my implementation wouldn't go anywhere near this far. The next component I want to point out is the Console component. This is the second most downloaded component and it's used by tons of open source projects. Even Composer, which is used to install this component, neat. Console is a larger package than Yaml, so the docs are multi-page. But the general idea is you create a console application, at a command, figuring out user prompts, optional versus required commands, flags, multiple progress bars, tables and more are all baked in. This is one of my favorite packages. Many projects these days require external resources. Pulling from an API or posting data. For this, Symfony has the HTTP client component. If you've had to work with native PHP cURL functions this will be a breath of fresh air. On top of that, the syntax is very readable and for more advanced use cases, there's probably an example in the Symfony Docs. Have you worked on a project that wouldn't benefit from some caching? The PHP-FIG group has a PSR for cache. If you're interested, check out PSR-6 and PSR-16. The Cache component implements PSR-6, but also provides a cool way to use one method to get and set a cache value. In addition, tons of common adapters ship with this component. Another common thing in PHP is manipulating files in the Filesystem. Sometimes this can be tricky if your code is running on different platforms. The Filesystem Component feels like working in your shell and in your PHP code. It's familiar, fast and abstracts away concerns about the OS. It pairs nicely with the Finder component that allows you to traverse the file system, looking for specific files. Both very cool tools that can be foundational to a project. I've spotlighted only a few of the 200 plus Symfony components. The important thing to keep in mind with these, is you can pick and choose what you need to support your project but still own some major architectural decisions. Is it MVC? Are you using a service container? Maybe it's console only. Symfony has components that will help move your project forward.

Contents