Home / Tutorials / Symfony 2.8 – A Microframework

Symfony 2.8 – A Microframework

A microframework is a term used to refer to “minimalistic web application frameworks”. Developers usually associate this term with “fast and small frameworks”, such as Silex. But you can also think of microframeworks as simple and less-opinionated fameworks where you opt-in to the the architecture-related decisions.

Thanks to its flexible internal architecture, it has been possible to use Symfony as a microframework since day one. However, few developers have used Symfony in that way because it wasn’t completely convenient.

Symfony 2.8 introduces a new microkernel trait to greatly simplify the creation of single-file (or just smaller) Symfony applications. A “Hello World” application using Symfony as a microframework looks like this:

A single MicroKernel class enables the bundles, configures them, defines the routing and even holds the controller code. If you exclude the mandatory use imports and the function declarations, the above example has exactly 4 lines of PHP code. Think about that for a moment: a fully-functional Symfony application in just 4 lines of code!

The new microkernel doesn’t improve the raw Symfony performance, because it just changes the way routes and bundles are registered. However, since you are only enabling the features you use, lots of the features and bundles of the Symfony Standard Edition are disabled. This explains the difference perceived in the application performance:

symfony 2.8

The best thing about the Symfony microframework is that you are building your application on the shoulders of Symfony, meaning that you won’t face any of the usual restrictions of the microframeworks. All the incredible Symfony features and bundles are ready to use in case you need them as your application grows.

In the following example, the Hello World application is expanded to add Twig templating support, the Web Debug toolbar and the Symfony Profiler. The result is still a single-file application:

Creating single-file applications is not the main purpose of this microkernel. The real use-case is to create smaller Symfony applications, perhaps having just one services.yml file, one config.yml file per environment and the routing defined as annotations in regular controller classes. This is the full code needed to implement this use case:

And don’t forget to update the front controller to use this new microkernel instead of the usual AppKernel:

So if you’re choosing between a microframework or the full-stack framework, you have a new possibility. Now you can have both at the same time in the same application and without compromising any features.

Source: Symfony Blog


About cmadmin

Web Developer & Designer | Android App Developer

Check Also

PHP frameworks evaluation – LARAVEL is best

I’ve evaluated several PHP frameworks like zend, codeigniter,cakephp,kohana and so on. I completed the feature/checkbox table, reviewed code within each one, moved on to finalist selections, ran a couple sample projects, and finally made the pick.


Create an Account!
Forgot Password? (close)

Sign Up

Confirm Password
Want to Login? (close)

Forget Password?

Username or Email
%d bloggers like this:
To get latest new / tutorial / technology / development information subscribe with us.
Lets Get Updated with latest trends & tutorials!
Your Information will never be shared with any third party.
Ready for latest tutorials & tools !