Symfony – Architecture
Symfony is basically a collection of high-quality components and bundles. Components are a collection of classes providing a single core functionality. For example, the Cache component provides cache functionality, which can be added to any application. Components are building blocks of a Symfony application. Symfony has 30+ high-quality components, which are used in many PHP frameworks such as Laravel, Silex, etc.
Bundles are similar to the plugin but easy to create and easy to use. Actually, a Symfony application is itself a bundle composed of other bundles. A single bundle can use any number of Symfony components and also third-party components to provide features such as Web framework, database access, etc. Symfony core web-framework is a bundle called FrameworkBundle and there is a bundle called FrameworkExtraBundle, which provides more sophisticated options to write a web application.
The relationship between the Components, Bundles, and Symfony application is specified in the following diagram.
Symfony is mainly designed to write high-quality web applications with relative ease. It provides various options to write different types of web applications from a simple web site to advanced REST-based web services. Symfony provides web framework as separate bundles. The common bundles used in the Symfony web framework are as follows
The Symfony web framework is based on Model-View-Controller (MVC) architecture. The model represents the structure of our business entities. The view shows the models to the user in the best possible way depending on the situation. The controller handles all the requests from the user, does the actual work by interacting with the Model, and finally provides the View with the necessary data to show it to the user.
The Symfony web framework provides all the high-level features required for an enterprise-grade application. Following is a simple workflow of the Symfony web application.
The workflow consists of the following steps.
Step 1 – The user sends a request to the application through the browser, say http://www.symfonyexample.com/index.
Step 2 – The browser will send a request to the webserver, say Apache webserver.
Step 3 – The web server will forward the request to the underlying PHP, which in turn sends it to the Symfony web framework.
Step 4 – HttpKernel is the core component of the Symfony web framework. HttpKernel resolves the controller of the given request using the Routing component and forwards the request to the target controller.
Step 5 – All the business logic takes place in the target controller.
Step 6 – The controller will interact with Model, which in turn interacts with Datasource through Doctrine ORM.
Step 7 – Once the controller completes the process, it either generates the response itself or through View Engine, and sends it back to the webserver.
Step 8 – Finally, the response will be sent to the requested browser by the webserver.