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.

5 comments

  1. michael kors handbags

    I抦 impressed, I have to say. Actually rarely do I encounter a blog that抯 both educative and entertaining, and let me let you know, you have hit the nail on the head. Your thought is excellent; the difficulty is something that not sufficient people are talking intelligently about.

  2. It is best to take part in a contest for among the best blogs on the web. I will advocate this website!

  3. WONDERFUL Post.thanks for share..extra wait .. ?

  4. Women Originals NMD Balck

    This really answered my downside, thank you!

  5. Adidas NMD R1 Pink Purple White

    you will have an important blog right here! would you like to make some invite posts on my blog?

Leave a Reply

Your email address will not be published. Required fields are marked *

Login


Username
Create an Account!
Password
Forgot Password? (close)

Sign Up


Username
Email
Password
Confirm Password
Want to Login? (close)

Forget Password?


Username or Email
(close)
%d bloggers like this:
SHARE
OR
SUBSCRIBE
To get latest new / tutorial / technology / development information subscribe with us.
ARE YOU READY? GET IT NOW!
Lets Get Updated with latest trends & tutorials!
Your Information will never be shared with any third party.
Ready for latest tutorials & tools !
OR SUBSCRIBE WITH