PHP Routing

If you’ve ever written web applications in Python using Pylons or TurboGears (>=1.1), you’re probably familiar with an incredibly handy tool known as Routes. It’s modeled after the Ruby on Rails routes system and does quite a marvelous job at mapping friendly, SEO URLs to useful code. If you’re not aware of it, you really should check it out.

However, I was curious to see if it were possible to create a Routes-inspired PHP library that would perform essentially the same task. I’m sure there’s an already-written PHP routes system, and I’ve allowed myself to fall into the not invented here trap. But, that’s part of the fun in coding: If you don’t like what someone else wrote or you want to give it a hand yourself, no one is stopping you. It’s great.

Thus, I’ve written Routing, the PHP routes system. It’s similar in syntax and intent to Python Routes with the exception that it’s PHPized (in other words: bastardized). If you read the sources, you might be able to see a little Python influence here and there (along with my frustrations toward PHP as a language vented in silence). I wouldn’t recommend it as anything short of entertainment as yet; I haven’t cleaned up the sources, and I expect they’re going to be really messy for a little while. The route search mechanism is awful, and I plan on refactoring it in a future revision. For now, the system works, and that’s good enough. (That’s my INTJ side talking.)

So, if you’re curious enough to take a look, head over to the Routing Trac page. I have some downloads posted there in a variety of formats (.zip, .tar.gz, and .tar.bz2). There’s no API documentation yet. I’m going to add it soon. Since Routing was born on Wednesday, August 5th, 2009 it’s quite young. However, I have some preliminary unit tests written (also incomplete) that you can read to get a general understanding of how Routing works. If you’re more interested in the principle behind Routing, you might want to read the documentation for Python Routes. Routes and Routing work roughly the same with the exception that Routing, unlike Python Routes, is extraordinarily buggy. I hope I can evolve this into something of an acceptable sibling to Routes but that will take time and a whole lot of effort. I have a few additional ideas, too.

***

One Response to “PHP Routing”

  • Benjamin writes:

    As an aside, Recess PHP has a rather interesting routing system I just took a look at today. It’s integrated into the framework and works differently to Routes (and Routing). I’ve been meaning to toy with Recess! at some point, but for special needs, I can’t see using a generalized web application framework (and there’s tons for PHP).

    Also, I may be revising some of the Routing internals–I haven’t really decided. I suspect I’ll be leaving RESTful delegation as something the host application should take care of, although the latest version I have of Routing (no packages yet–I still have to check it into SVN!) does make some implementation of RESTful services available (via delegation).

Leave a comment

Valid tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>