In this episode of the series we are going to ensure the durability of our code by including one of the most important components of the modern application design - Unit Testing.
We’ve been working on our framework for quite some time now. We’ve been adding some important features by enabling new Symfony2 Components. But with the time our code base grew and now if you take a look our “framework” code it’s a mess. It’s time to do some serious refactoring. And from now on the framework we’re building will have a name – Simplex!
In this episode we’re going to do the following:
- the front controller (/web/front.php) will be the boiler-plate to initialize the framework and the application
- the framework itself (/src/Simplex) will abstract the handling of incoming Requests into class that could be reused when creating other web sites and applications
- the application (/src/Calendar) will handle the business logic – in our case will calculate the leap year and do other interesting stuff with time continuum
- the configuration (/src/app.php) will take care of routing and customization of the framework
We’ve been stuck with procedural code in our framework for the educational purposes. It is time to grow up and use object oriented style. In this episode we’ll convert our controller to the class. Then we’ll optimize the object instantiation by using another handy Symfony2 Component - HTTPKernel.
Today we’ll cover on of the corner stones of modern application architecture – the controller. Its mission is to generate a Response based on the information provided by the client Request. Put in simplest terms: the controller contains the business logic of your application. Say, a client requests an URL
example.com/is_leap_year/2012. Instead of writing everything inside of the file leap_year.php where the presentational markup and programming logic get mixed, we’ll move the leap year calculations into a very digestible container – the controller.
In the second episode of the series we’ll look at the most fundamental component in the Symfony2 Components suite - HTTPFoundation Component.
Symfony2 had taken a step back from the ugly global variables and based its architecture on the most basic principles: Requests and Responses.
Using these makes building your PHP applications fun again!
The screencast series is based on the blog posts by the creator of Symfony2 Fabien Potencier: http://fabien.potencier.org/article/50/create-your-own-framework-on-top-of-the-symfony2-components-part-1
In this episode I’ll walk you through the bootstrapping process.