This morning I made a compilation of the bundles that I almost always end up installing in the projects that I develop with Symfony. They are not all that are or are not all that they are but I think that because of the functionality they provide and the versatility they offer when configuring them, it was worth talking a little about them. So … here we go!
Any compilation that is worthwhile should contain this fantastic bundle provided by Friends of Symfony which provides the basic functionality to work with users in Symfony.
Among its main features is the definition of a basic model to define the user entity, a
provider to load users by username or email as well as the entire process (along with its routes, forms and controllers) so that users can register, start session, validate your account or recover the password.
All this makes FOSUserBundle the best starting point if you have to integrate user accounts into your application.
Update. Thanks to the MakerBundle it is also possible to create the repetitive code of our authentication system in a fairly simple way using the commands make:
make:registration-form . So if you are already familiar with Symfony 4 and the management of users and authentication this is the best option, especially in the case that you are going to need to expand the system logic with yours (something that with the FOSUserBundle complicates something else because it is necessary to resort to the system of events that it has implemented to modify it).
For me, the best bundle you can install if you need to mount an administration panel for your application.
Although SonataAdminBundle can have a somewhat higher learning curve than EasyAdmin, its great versatility allows us to create a panel that meets virtually any need we have. CRUD operations are configured through special services labeled
sonata.admin, and their implementation is very fast, just 50 lines of code.
blocks can be created to add extra functionality to the panel. And yes, it also supports exporting data to various formats natively.
Again Friends of Symfony goes to the rescue, this time to help us integrate ElasticSearch into our application. FOSElastica, based on Ruflin’s Elastica library, allows us to define, by means of a
yaml file the indexes and the types of documents that we will store in them and the mapping of our entities in such a simple way that it seems magic. Again, another essential bundle.
In addition it is regularly updated to support the new versions that are coming out of ElasticSearch so we can be guaranteed that it will integrate seamlessly with this fantastic service.
4. Doctrine Behavioral Extensions
In case you need automatic actions on your entities such as generating the slug from other properties, setting the creation or modification date automatically or adding the possibility of translating them, Doctrine Behavioral Extensions are your best option.
After installing them, we will access all these functionalities by simply defining the relevant annotations in the properties of your entity (or through a
yaml file if you are using this configuration method).
If you need to add the possibility of logging in using Facebook or any other social network, HWIOAuthBundle is perfect, since by simply defining the right listeners the login through third parties will be perfectly integrated into your application.
It is also compatible, as it could not be otherwise, with FOSUserBundle, so both will solve the entire tedious process of adding a login to your application. And yes, it also contemplates and solves the problem of duplication of users when their email already exists and signs in through a social network, something that is not always well managed.
Before we talked about SonataAdminBundle as one of the best administration panels you can find. Well, SonataMediaBundle makes working with images or files really easy from that same panel.
In addition, it has direct integration with Amazon which allows us to work with S3 as a CDN very easily. It also provides the possibility of establishing contexts, which serve to specify the size of the “thumbnails” that will be generated when an image is uploaded, something that is appreciated, thus saving us a lot of time.
With the appearance of React, Angular and the rest of the frameworks for frontend development, it has become essential to be able to set up API’s quickly and easily.
For this, the best option is to use the API Platform bundle which can be installed using a composer / flex recipe and which solves in a very simple way the creation of a basic API for our entities. It also has a very extensive documentation and has native integration with Mercure (protocol to send push updates to browsers).
Other option is FOSRestBundle. With this bundle we can create a Rest API from 0, specifying the characteristics of each route, the format in which the data will be returned (JSON rulez) and use the different serialization groups that we define to return certain properties of our objects based on The route accessed.
If we need to serialize our entities (for example, to send them to third-party services such as Algoria), Symfony has a component called Serializer that allows you to carry out this task quite simply. As soon as we install it, we will have a complete serializer that will also provide us with options such as the possibility of specifying serialization groups (since we will not always want to serialize all the properties) and the definition of callbacks to control the entire process.
Another option is to use the JSMSerializer bundle which, however, is already being replaced by the native Symfony component. Like the previous one, it allows you to specify the properties that will be returned through serialization groups and hook us through events to the different parts of the process.
The arrival of webpack was a real revolution in managing the css, js and assets of our application. WebpackEncoreBundle allows us to integrate it directly into our application and can also access all its options through its own configuration file resident in the root of our project. An essential bundle especially now that version 4 of Symfony recommends it as a method to organize our assets.
This bundle which allows us to generate PDF’s as if it were HTML files, since what it does is receive a Twig template and generate the corresponding pdf. In our opinion, KnpSnappyBundle is a natural substitute for the FPDF library, since it greatly speeds up the process of generating PDF’s. Of course, it requires that you have the WKHTMLTOPDF library installed on our server.
And with this ends this small list of bundles that I use more regularly. As sure that I have left some I encourage you to leave it in the comments so that the rest of readers can meet them.
¿Quieres recibir más artículos como este?
Suscríbete a nuestra newsletter: