I built a simple routing framework for PHP called Wayfinder

Week 188 was posted by Charanjit Chana on 2021-06-01.

Building a framework isn't actually something I set out to do, but as a learning exercise it was a great thing to do.

I am an avid fan of the CodeIgnitor framework, I’ve approached a lot of simple projects with a MVC mindset. While I would normally reach for CodeIgniter itself as the base of a project, a few years ago I decided to build out my own framework as a learning exercise. Primarily for routing, which is all I really needed, the ‘framework’ formed the basis of a number of projects. It has worked out pretty well for me but updates and bug fixes aren’t necessarily compatible between them all as they diverged depending on their needs.

Earlier this year, I decided to formalise what I had been working on. Wayfinder was born, again its primary purpose is to handle routing. If nothing else, you can just use it to point URLs to functions in your code. If you want to take it further, it ships with a very basic DB class for MySQL, and it lets you set out your code in the same style as other MVC frameworks.

Having this architecture means you can clearly separate your code according to MVC principles. If you want to. Nothing is prescribed but it's all fairly well documented.

I'm hoping the examples page does a good job of explaining how routing works. In truth, if you've used a framework like CodeIgniter before, then it's nothing new. The framework itself (including documentation) weighs in at under 150kb which means it a pretty lightweight framework.

Right now, the framework has been through 12 per-releases and in all honesty, it may never experience an alpha, beta, or 1.x release. Of course I hope it matures a bit more, but the journey alone has been really interesting. It got me back into unit testing PHP and I've pushed PHP itself further than ever before.

Having said that, you might take a look at usewayfinder.com and think that the documentation makes it look like something intended for public release. It’s really not at the moment, but I figured it was worth putting the effort in for myself. I know all too well how far projects can diverge away from each other so keeping to the core principles from the start will be good for me. There’s also a bit of added responsibility now, so I’ll do my best to keep project specific code in the projects and anything generic enough should be rolled into the framework.

Moving from SVN to Git

Source control is source control. I don't really mind where it sits but my code has rarely been pushed to a git repository. I’ve used SVN for most of my career, so this switch has been a really good bit of learning I had avoided for a number of years.

Wayfinder's command line interface

Wayfinder works on the command line and I’ve kept the same structure as used for serving pages to visitors. Just pass your path as the arguments and you’re routed to the right bits of your code. It’s easy to use and easy to explain, I think.

It’s been a couple of months now since my last round of changes. I’m not sure how much further I’ll push it all and I may even end up using Laravel or Symfony for future projects as they’re likely to scale better for bigger projects. For now though, routing through Wayfinder has given me a really good tool to prototype with and then expand as required.

Tl;DR:

Wayfinder is a routing framework for PHP, built to help standardise how I approach my own personal projects.


Tags: development, mvc, php, wayfinder


Tweet WhatsApp Keep Upvote Digg Tumblr Pin Blogger LinkedIn Skype LiveJournal Like