Archive for July, 2007

The future of symfony routing

If you follow the symfony timeline, you probably saw quite a few changesets dedicated to the routing functionality lately. Fabien has been refactoring the routing to make it a normal object - not a singleton - in the trunk; and I have been working on expanding the route syntax in the routing branch.

If you look closely, it means that routing will be more powerful, easier to tweak, and faster.

With the new routing system, routes can use any separator between tokens. For instance, you can have such rules that were not possible before:

permalink:
  url: /:day-:month-:year/:title
  params: { module: content, action: permalink }

multiformat_list:
  url: /articles/list.:format
  params: { module: article, action: list, format: html }

The route syntax was originally a port of the Ruby in Rails routing system. That explains why tokens are prefixed by a colon (:), but that doesn’t really make sense in PHP. That’s why the new routing system now accepts tokens prefixed by a dollar sign ($), which will look more familiar to PHP developers:

permalink:
  url: /$day-$month-$year/$title
  params: { module: content, action: permalink }

multiformat_list:
  url: /articles/list.$format
  params: { module: article, action: list, format: html }

A new default rule was added to the routing.yml, and together with a hook in the controller, it allows for built-in support of PJS templates. That’s right, the ability to include dynamically generated JavaScript files, available in symfony 1.0 with sfPJSPlugin, will be a native functionality of symfony 1.1. This implementation allows for caching of generated JavaScript files with the regular caching system.

<?php echo pjs_include_tag('foo/bar?id=12') ?>
// will generate in HTML
<script language="JavaScript" type="text/javascript" src="/js/foo/bar/id/12.pjs"></script>

There is more to come, but the limits are already pushed much further than where they used to be.