ActiveBlog

Using PHP Beautifier with Komodo IDE
by

, March 26, 2009

Update: adjusted the PHP Beautifier instructions slightly as per @h

Komodo IDE recently added a code formatting feature, including built-in formatters for javaScript and HTML/XML. This is great, but the first thing I wanted to do was format PHP code! Luckily Komodo also allows the ability to add new formatters by hooking into existing command-line utilities.

For PHP code, my favorite formatter is the PHP_Beautifier PEAR module, which helpfully installs a 'php_beautifier' script you can run from the command-line. All I did was install PHP_Beautifier via PEAR:

pear install PHP_Beautifier-beta

This should install the 'php_beautifier' script; I'm using MAMP on my MacBook so mine ends up in

'/Applications/MAMP/bin/php5/bin/php_beautifier'.

To integrate this script with Komodo, do the following:

  1. Open Komodo's preferences window and click on 'Formatters' on the left-hand side
  2. Click on the green 'Plus' button to add a new formatter:
    Picture 2.png
  3. Type in the following:
    Name: PHP Beautifier ( or whatever )
    Language: PHP
    Formatter: Other Formatters => Generic Command-line Formatter
    Picture 3.png
  4. For 'Executable to use', paste in the full path path to the 'php_beautifier' script.
  5. For the command-line arguments, paste in the php_beautifier options you would like to use.

Now, how you would want to format your code is entirely up to you. I f you;re developing Drupal code, you might want to look at their style guide; for other projects, YMMV. For my own development, I have arrived so far at this:

-s4 -l "ArrayNested() NewLines(before=if:switch:T_CLASS:function:T_COMMENT:T_VAR,after=T_COMMENT:function)"

The nice thing is that you could create several of these for different code formatting standards.

Subscribe to ActiveState Blogs by Email

Share this post: