Inflect Shell - Inflect the heck out of your word(s)

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 a defunct cms. 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 would not be an efficient use of my time. 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).

The code for this is available in the inflection plugin on github.

Note: For the record, the correct rules for turning phrases into fieldnames are Inflector::underscore(Inflector::variable('phrase goes here'))

blog comments powered by Disqus