Inflect Shell - Inflect the heck out of your word(s)
I'm a rather silly goat, so I like doing what is potentially frivolous if it means wasting time. This is one of those random frivolous projects.
CakePHP provides us with a nice little Inflector class. It's quite useful in creating slugs, as you can see from Mariano Iglesias' Sluggable Behavior. You can also use it to see what you should name your tables based upon your model name (is the tableized form of 'Person' 'person' or 'peoples'?). To initiate such tests, though, you'd usually need to either embed the code in an app - why are we using an entire app to variablize a phrase? - or use something like Matt Curry's Interactive Plugin for the DebugKit. Both slightly lame because of the setup.
Anyways, I needed to turn a word/phrase into what the fieldname in the database would be in order to properly capture it for usage in Marcy Avenue. I then thought of using the Interactive Plugin, but didn't have it installed in the app, and I thought refreshing pages/changing code to find out what methods to use was just silly. So I spent around 3 hours coding up a little shell to do it instead :P
Usage is simple:
cake inflect
cake inflect methodName
cake inflect methodName word
cake inflect methodName words to inflect
It'll prompt for any missing information/anything that isn't correct (there isn't a 'helff' Inflector method, for example). This only does rules in the Inflector Class included with CakePHP as of today, 11/28-2009, so don't complain if we have new rules 10 years from now.
Note: For the record, the correct rules for turning phrases into fieldnames are Inflector::underscore(Inflector::variable('phrase goes here'))