Integrating Your Own Tools into PHPStorm / Clearing the Magento Cache through the IDE

As a Magento developer, I am already used to constantly clearing the cache and have created a Bash alias, "clear-magento-cache", for my Linux workstation.

alias clear-magento-cache="rm -Rf var/cache/mage--\*"

I always run this command in an open terminal window. As you can see, though, I have to leave my IDE to do so. It would be better if I could click a button directly in the IDE. Since I have been getting to know PHPStorm for a while now (you discover something new every day), I thought I would see what the IDE offers here. And I discovered something new again.

In the settings, Ctrl + Alt + S, under "External Tools", you can add your own tools. These can then conveniently be organized into groups. So I created a new entry here in the "Magento" group.

For "Program", you simply enter "rm". Under "Parameters", enter the following:

-Rf $ProjectFileDir$/var/cache

As you can see, you can conveniently get the current project directory through a variable. In PHPStorm, this is called a macro. There are plenty of other useful macros. The "Insert macro" button lists them all.

We now give it the name "Clear Magento Cache".

That is really all you need for the actual functionality. The finished command can now be run from the menu under "Tools -> Magento -> Clear Magento Cache".

Now all that is missing is the toolbar button. Simply right-click the toolbar. In the context menu that appears, select "Customize Menus and Toolbars...". In the "Main Toolbar" folder, select the last command ("Task toolbar" in my case) and click the "Add After" button on the right.

A dialog opens, and we can select our new command under "External Tools". Optionally, the "Set icon" button lets you add a 16x16 pixel icon.

I will definitely be expanding my use of this feature in the near future. Another nice thing is PHPStorm's built-in Phing support. My tip: simply call the build script through "External Tools" and pass the build task as a parameter. This lets you quickly build a command using internal PHP functions.

Have fun tinkering.