 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 12)
by Chris Cornutt January 25, 2012 @ 08:36:48
In this final post of his series about building a framework on Symfony2 components, Fabien Potencier focuses again on flexibility - allowing you to have more than one front controller with different configurations thanks to dependency injections.
Does it means that we have to make a choice between flexibility, customization, ease of testing and not having to copy and paste the same code into each application front controller? As you might expect, there is a solution. We can solve all these issues and some more by using the Symfony2 dependency injection container.
The Symfony2 DIC (DependencyInjection) allows you to create a container with the objects and settings that you want and inject that into the main "Framework" class for its use. He registers most of the components he's added over the series like the UrlMatcher, RouterListener, ExceptionListener, EventDispatcher and the Framework class itself. This is all stored in a separate file(s) and can be conditionally included based on your environment. He shows how to register a custom listener, add parameters to the DIC configuration.
voice your opinion now!
symfony2 framework component custom tutorial series dependency injection
Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 11)
by Chris Cornutt January 24, 2012 @ 11:04:44
In part eleven of his "Build a Framework on top of Symfony2", Fabien Potencier improves on his earlier versions of the code by adding in the HttpKernel support for handling events and errors that might come up in the application.
If you were to use our framework right now, you would probably have to add support for custom error messages. Right now, we have 404 and 500 error support but the responses are hardcoded in the framework itself. Making them customizable is easy enough though: dispatch a new event and listen to it. Doing it right means that the listener has to call a regular controller. But what if the error controller throws an exception? You will end up in an infinite loop. There should be an easier way, right?
Using the "RouterListener" functionality, he sets up an "ExceptionListener" and points that to an error handling controller with its own "exceptionAction". This action takes the exception information and displays a "Something went wrong!" message along with the details. He also includes an update to the Response handling to allow for returning a string back from the controller instead of a Response object.
voice your opinion now!
symfony2 framework component custom tutorial series
Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 9)
by Chris Cornutt January 19, 2012 @ 08:58:11
Fabien Potencier has posted the ninth part of his "build a framework on Symfony2 components series. In this latest tutorial he takes the simple framework he's already created (complete with some unit tests) and makes it easier to extend.
Our framework is still missing a major characteristic of any good framework: extensibility. Being extensible means that the developer should be able to easily hook into the framework life cycle to modify the way the request is handled.
He chooses the Observer design pattern as a basis for his example, allowing any kind of behavior/actions to be added to the framework's execution. He includes the Symfony2 dispatcher to make this work and includes the code for a "handle" method to fire off events. It executes a "ResponseEvent" every time the framework is executed. An "addListener" method provides the hook to apply a callback to an event - in his case an anonymous function (or closure).
voice your opinion now!
symfony2 framework custom series extensible observer designpattern
Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 7)
by Chris Cornutt January 16, 2012 @ 08:46:22
Fabien Potencier has posted the seventh part of his series looking at how to make a custom framework on top of the components from the Symfony2 framework. In this part of the series he improves his basic framework by adding some namespacing to organize the application a bit more.
If you have a closer look at the code, front.php has one input, the Request, and one output, the Response. Our framework class will follow this simple principle: the logic is about creating the Response associated with a Request. As the Symfony2 components requires PHP 5.3, let's create our very own namespace for our framework: Simplex.
He puts the main front controller in just the "Simplex" namespace but adds in others for the controllers and models. He also updates his Composer configuration to create some PSR-0 autoloading.
voice your opinion now!
symfony2 components framework custom tutorial series namespace autoload
Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 5)
by Chris Cornutt January 12, 2012 @ 10:48:17
Fabien Potencier has posted the fifth part of his series looking at building a custom framework on top of the Symfony2 components. In this new tutorial he adds in one of the major features of any framework - the controller level.
For simple pages like the ones we have created so far, that's not a problem, but if you want to add more logic, you would be forced to put the logic into the template itself, which is probably not a good idea, especially if you still have the separation of concerns principle in mind. Let's separate the template code from the logic by adding a new layer: the controller: The controller mission is to generate a Response based on the information conveyed by the client Request.
He updates the template rendering to use an external method instead of doing it itself and updates the routing to include a "_controller" attribute pointing to the method. The full code for the updated version of the framework is included - a simple request/response with handling for a "leap_year" route.
voice your opinion now!
framework symfony2 custom controller tutorial series
Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 1)
by Chris Cornutt January 04, 2012 @ 08:47:39
Fabien Potencier has written up a new post on his blog talking about creating your own framework layered on top of the Symfony2 framework's component system (yes, a framework from a framework).
Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP components that solve common web development problems. Instead of using these low-level components, you can use the ready-to-be-used Symfony2 full-stack web framework, which is based on these components... or you can create your very own framework. This series is about the latter.
He talks about the reasoning behind wanting to make your own framework, mostly dealing with exploration and/or proving you can do it. He walks you through every step of the way - creating the base directory, setting up a project via Composer, creating an autoloader and making a first basic file - a "Hello world" echo message. In the next part of the series, he'll add in the HttpFoundation component for web interaction.
voice your opinion now!
framework custom symfony2 component tutorial series
|
Community Events
Don't see your event here? Let us know!
|