Weekend. Music. Coding. Three words that when brought together means changes to Pundit. And since I was getting bored with two specific things in the framework I had to go and change both. And of course one breaks all things known as backwards-compatibility.
So.. Here’s a quick intro to the things I got bored of typing when coding, and how I changed Pundit to reflect that.
There is actually two things wrong with this. A, it’s annoying to look at, and B, it’s just not spiffy. Hence I changed the standard runner (PunditRunner) to do the following:
If the request is for a method that doesn’t exist, but the show() method exists, it will change the method to show and add the method to the list of parameters, then call show(). Hence you will only need to do like this:
>?php
class controllerController extends PunditControler {
public function show( $id ) {
// ...
}
}
?<
And really - that’s how you would have done it with the “old” urls, so no changes except to your views to enjoy this change.
Okay, this was just my bad thinking from the get-go that got me stuck typing all those “->get()”s. I should have just started out the way it is now. But the reason for doing this was very simple: What if I want to add parameters to get() while using the ArrayAccess-interface. There was no obvious way to do this. And since I use the same interface to the PunditFilter which all things $_REQUEST comes through it wouldn’t take long before you wanted to add parameters.
But today I came up with an idea. What if you just ask for variable_name.type eg $_REQUEST['foo.int']. That would be a simple and effective way of doing said trick. So off I went and changed the inner workings of PunditModel::getVar and PunditFilter::offsetGet.
Wait. I know there was something I forgot. It couldn’t be _that_ easy. Only 10 lines of code added. Trying to load my web-application. Nothing worked. Ahh - there was something I forgot. All the places in Pundit and my application that referenced “->get()”. Which was quite a few. 255 places to be exact. So up went the volume on the music and I started working my way through the list.
But it got done, and it was for the better. So, now you know, kids. Don’t do the bothering fix to a problem you can’t find a good solution for. Wait and think about it. Wait. Think. Come up with a good solution. Implement. I didn’t and I had to do 255 manual code-replacements.
-fangel
March 18th, 2007 | Pundit