Kris Wallsmith

Symfony Guru at opensky.com.
Discussing web development, Symfony and fatherhood.

May 19

Waiting for the Metro, thinking about Forms

I’m below Paris waiting for the 13 and thought I might take advantage of this time to post here…

Things are good! My first days at Sensio have gone well, although I’ve been bailing around lunchtime to catch up on sleep. Fabien and I have been working on that-which-cannot-be-revealed and discussing bits of symfony, components and the like.

I recently introduced the sfFormSymfony class in the 1.3 branch, which includes this pearl of a method:

$form->bindRequest($request);

So clean, so simple. Compare that to the code necessary to do the same thing in the 1.2 branch:

$form->bind(
  $request->getParameter($form->getName()),
  $request->getFiles($form->getName())
);

Ugly, huh? Fabien’s term was “not ugly, explicit” (I couldn’t help but laugh at his turn of phrase).

We dicussed this point for awhile, and there actually some decent arguments against this enhancement. One, surprisingly, is simplicity. This is one of those terms that can mean a number of different things, depending on who you talk to. For me, the new bindRequest() method is a clinic in simplicity.

This simplicity has its limits however. For example, if I were new to symfony and was told to use this method when binding forms in my action layer, I would be very happy. It’s so easy! I may even blog about symfony and tell everyone to use it… But what would I do when it came time to unit test my form? There is no request object, so how do I bind a request to my form now? I don’t know. I guess I won’t unit test my form…

This is a big concern. It’s hard enough to get developers to write automated tests, this runs the risk of only making that harder.

There are other considerations, but those are more easily addressed with enhancements currently in the hopper. So, the jury is still out. I will continue to add this method to my 1.2 projects, but its inclusion in 1.3 is far from assured.