Features

Composer support in PhpStorm

One of the great things that happened in PHP world was the introduction of Composer, a dependency manager for PHP which allows us to specify dependencies for our project and have Composer install and update them for us. With PhpStorm 6, we’re taking Composer support one step further with full support for this great tool in the UI and in PhpStorm’s command line tool.

In this post, we’ll cover our new tooling support:

  • Creating a new project with Composer
  • Init Composer
  • Add dependencies
  • Command line tool support

Let’s create a project using the Symfony framework and install dependencies using Composer support in PhpStorm.

Creating a new project with Composer

When creating a new project in PhpStorm using the File | New project… menu, we can choose from a list of project types. PhpStorm 6 introduces a new project type: Composer project.

When using this project type, PhpStorm will present us with a dialog which allows us to do two things. We can specify the path to composer.phar (or have PhpStorm download it from getcomposer.org) and we can start adding dependencies through Composer. Using the package filter we can search through packages listed at the Packagist.

Let’s install the symfony/symfony package, the official package for the Symfony framework. By default the latest version will be installed, however we can select the version to install from this dialog as well. After clicking OK, PhpStorm will install the selected package into a new project.

Once finished, we have a blank Symfony project which we can start developing in.

Init Composer

In an empty project (or an existing project in which Composer was not initialized), we can right-click the project and use the Composer | Init Composer… context menu to enable Composer support for our project. If you don’t have composer.phar anywhere on your system, the Click here to download from getcomposer.org helper will download the latest composer.phar from the official website.

This will generate a default composer.json file in our project in which we can describe our project and its dependencies.

Add dependencies

Why type raw JSON in the composer.json file to add dependencies? Not to mention that Composer should be invoked to install dependencies described. PhpStorm 6 comes with a new context menu which is displayed when right-clicking our project: Composer | Add dependency…

Imagine we would like to create spreadsheet documents in our application. We can add a dependency to the phpexcel/phpexcel package with the click of the Install button.

PhpStorm will add the dependency to composer.json and satisfy any other required dependency automatically for us.

Command line tool support

When full control is needed, we can always use the command line tool in PhpStorm to invoke Composer. We can bring up the command line tool using the Tools | Run Command… menu or with Ctrl+Shift+X (Cmd+Shift+X on Mac).

PhpStorm comes with full Composer framework support in the command line tool. When we start typing “composer”, PhpStorm will come with a list of suggestions and autocompletion support.

Please download the latest build, provide as much feedback for bugs and feature requests here, and leave questions in the comments below or in our forums!

Develop with pleasure!
– JetBrains Web IDE Team