eZ Publish and Symfony

The great news, that ezpublish will use the symfony framework as base for the next major release has spread now for a while and everybody (especially me, as being a ezPublish and Symfony developer) is very happy with this radical change in the develpment strategy of EZ Systems.

But it will take some time, until the new version is stable and can be used in production. Also we will be stuck with all these already running versions where there is no budget to upgrade and migrate the code to symfony. However, some of the symfony goodness can already be used with old ezPublish versions.

I recently came across this idea while developing a custom eZPersistantObject with +10 fields and frontend data entry. For persistant objects the neat content class features can not be used and validation/santization has to be coded by hand. If your are a eZ developer, you know what pain it can be.

$http = eZHTTPTool::instance();
$errors = array();

$errors[] = ‘First name is required’;

if(strlen($http->variable(‘first_name’)) < 2){
$errors[] = ‘First name has to be longer that two characters’;

$errors[] = ‘Email is required’;

$errors[] = ‘Email has to be a valid email address’;

As cool and awesome ezPublish is on the one hand, sometimes (especially with modules) you feel like back in the 90’s when only plain PHP files where used.

Now what I did to get around the pain, was to use the Symfony Validation component that is a standalone component that can be used for data validation. Since the eZ autoloader already understands namespaces, the usage is really simple. Just drop the code to some lib folder in your extension, regenerate the autoload array and feel the pain release.

One thought on “eZ Publish and Symfony

Leave a Reply

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