PHP-to-Ruby Rails Plugin
Aight, the alpha-version of my php/rails plugin is up. There is a ton of work left to do on it. I’ve yet to compile the various snippets that I have scattered amongst my projects, but this should get some aspiring neophyte php programmers into switching to the non-Dark Side of web development.
Install it with
./script/plugin install svn://ahgsoftware.com/php_compat/trunk |
And here are some examples
1 2 3 4 5 6 7 8 9 10 |
# Dates PhpCompat.date("F j, Y, g:i") # Translated to Time.strftime chars PhpCompat.time # Integer unix timestamp # Posix methods PhpCompat.get_pwnam('localusername') # Struct with passwd info # File methods (not network enabled... yet!) PhpCompat.file_put_contents('/tmp/file.txt',"yo yo yo") PhpCompat.file_get_contents('/tmp/file.txt') |
A few caveats..
- The php date-format to ruby Time-strftime translations are about 90% complete. There aren’t any convenient fallbacks, so certain formatting characters will not translate at all.
- The posix functions are POSIX functions!! So don’t expect much luck on Windows, although, they work great on OS X (naturally ;) )
- File methods don’t work on url’s yet
- There are some functions that I’ll never translate, as some things you just HAVE to do the ruby way. Its so much more concise, readable, and effective when you do it the ‘matz way’.
Since the main focus of this plugin is to make software migrations a bit less painful, the next set of methods that I wanna stick in there, is the mysql functions. I’ve used this in migrating thousands of lines of php code to ruby, so, I hope it helps someone else out too!
