PHP tools and libraries for Rails loyalists

I find myself in the thick of learning PHP, and I’ve got to admit, I’m having difficulty weaning off Ruby. If you’re in a similar position, you might find the following libraries and tools helpful – with a little less work, you can still build apps the Ruby way.

YAML loading with Spyc

YAML may just be a textual data format, but using it feels like a very Ruby thing to do, probably because most of us were introduced to it through Rails, where it’s used to describe database connections and test fixtures. Plus it doesn’t hurt that the yaml4r core library makes it dead easy to convert Ruby objects to yaml output.

It’s still good on the PHP side of things. Spyc is a YAML loader/dumper for PHP written by pre-eminent Rubyist Chris Wanstrath. (Coincidence?) Taking a cue from Rails, I’ve used it to configure database connections for a toy PHP app I’m putting together, and it works like a charm.

Update: Looks like we’ll see a Zend-friendly YAML parser soon.

Prototype and Scriptaculous

Okay, obviously Prototype and Scriptaculous are popular Javascript libraries that can be used outside of Rails, but what you might not be familiar with is Prototype’s Ruby-like syntax for Enumerable objects, complete with iterators and code blocks. If you’ve grown a fondness for Ruby methods like Enumerable#collect or #detect, then you might want to go with Prototype over other offerings. AJAX helpers are great, but these little language tweaks help make Javascript programming fun. Justin Palmer has a great tutorial on Prototype enumerables, if you’d like to read more.

Build Management with Rake

Rake is a build tool whose syntax is pure Ruby. You get all the mechanisms for describing build dependencies ala Make, combined with the flexibility of a fully featured programming language. Most people are introduced to Rake through Rails, but it can be used for anything – even building C programs. The popular Rails deployment tool Capistrano is actually a set of Rakefiles, which can also be used to deploy your PHP application.

PHP Reflection

Last, but not least, PHP 5 introduced reflection capabilities some time ago. Given the dearth of information available, I don’t think they’re used very much, but if you’ve grown accustomed to polling Ruby objects for their public interfaces, you might want to take a look. Matthew O’Phinney has a good overview of uses for reflection in PHP.

That’s what I’ve come up with so far. Any suggestions? I’ll add them to the list.

Side note: There’s always Symfony and Cake, but I figure if you’re moving from Rails to PHP, you’re probably working inside somebody else’s custom framework anyways.

Commentary

I’m trying out cake right now as we speak….and all I can say is where is my accessor in the model???!!!! Lol. Why can’t more hosts support ruby. Also as a I side note, I noticed that codeigniter is a lot faster than cake. However cake has a more RoR feel so I have stuck to that.

Comment by Justin on March 20, 2007

Spyc! My dark, dirty past has been unearthed!

Comment by Chris on March 21, 2007