gdahboy
Posted on October 6, 2019
Table Of Contents
*Introduction
*Component
*Form
*Translation
*Bundle
*Doctrine
*Annotations
*Migrations
*Services
*Logger
*Performance
*conclusion
Introduction
Symfony is a full-stack web framework, built with a lot of reusable set of standalone PHP components that solve common web development problems.
Component
Component they are the core of the framework, they are libraries that contains a lot of useful reusable code like
-Form
-Finder
-Filesystem
-Asset
-Mailer
-Routing
-EventDispatcher
-Translation
let's take some of them as example
From
the form component is a very useful tool, the general idea behind is to create an object that represents a form in that object you can specify every detail related to form in front-end {design, behavior...} and backend {field, entity, form relation ... }
Translation
this component is really useful you can use it in order to internationalize your application. instead of rewriting much text, you can create some sort of Dictionary. So your Application will be smart to detect when and what language to be used every Request.
Bundle
Bundles are a great way that Symfony Developer's use to write reusable code. let's take an example , You are creating an E-commerce Web application . in this type of Application there's a lot fo common aspect like : Facture , Product , Product-Basket , Product-Categories , Client , Coupons , third party library of payement 💰 💴 💵 and a lot more . you will need this entity each time + integration of some of libraries . Bundles has giving us the ultimate Solutions . we create an e-commerce Bundle and every time we have the e-commerce we can include it with it's entity , Repository , Interfaces that will be automatically integrated to the new template thanks to Twig
Doctrine
Symfony doesn't have it's own object mapping library . it used Doctrine Library , which used by many PHP frameworks like laravel and zend.
Annotations
Annotations are a great way to describe your data into php classes , you can specify every attribute as table column in your database . you can also add some parameters to the field like required , unique and other constraint related to size , type , range and you can even create your own parameters . this is only the start , through annotations you can represent entity relationships and lot more !!
Migrations
migrations is very similar to VCS , every time you make an update to your data structure you create a migrations (in git language we call it 'commit') and you can migrate throw migrations using version that stored in your database . it's really a cool 😎 thing i used it a lot !!
Services
we have covered a lot yet , but we have maybe reach only 5% of Symfony. So how can this framework manage all this library 📚 together. How can he manage to initialize a lot of classes without being worried about performance? Well through Services this is possible by initializing core functions once in all the platform and re-use this instance every time. Let's s an example of Mail Component Service .
So there's an object called Container that already contains many services . to make things more simple , let's say that services are some instances of class library 📚 . Implementing Services is really easy you can do that through controller or in services configurations in services.yaml . Once i have used Services to automatically logout every user after a 30min of an active session i created a class with 4 arguments in it's constructor that give the functionality of ending user's session . then i have add the class configuration in services.yaml file with all it's 4 argument .So symfony will automatically initiate the class and use it automatically every time he need it . Cool 😎 isn't it ?
Logger
Logger is a very cool part of symfony. it gives us a great tool to check for session , cockies , routes , sql requete , performance , reponse time ... and every details you would ask for . so go to your configuration files active the dev mode and here you go , you got your interface ready .
Performance
one of the biggest concern when we care about before we start using any language or framework is performance . PHP is one of the greatest scripting language in web development , but to be honest is not that great if we look
conclusion
thank you for reading my article . i really recomand Symfony for complex project or a group project . it can be hard at the begging but you will find very easy when you understand the core concept of it .
Posted on October 6, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.