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

This blog is permanently closed.

For up-to-date information please follow to corresponding WebStorm blog or PhpStorm blog.

 
This entry was posted in Cool Feature, PhpStorm and tagged , , , . Bookmark the permalink.

7 Responses to Composer support in PhpStorm

  1. It would be great to have some kind of overview/notification view green red bubbles to see if there is a new version of a library.

  2. Pingback: Gestionar depencias usando Composer & phpStorm ← TodoDev

  3. Adam says:

    How do I use this with a project that is already using composer? In my current project, the command line stuff doesn’t seem to work. When I type ‘composer install’, it tells me the command is not found.

    • Mikhail Vink says:

      There should be no problem in using it for already installed composer.. Have you configured Command Line Tool in Settings | Command Line Tool Support? “Tool path” should be a valid path to “composer.phar”

      • Adam says:

        Ahh, that did it. I had defined the path to composer.phar in the project settings. Didn’t realize that I had to define it separately for the command line tools.

        Thanks!

  4. Pingback: Adding Doctrine2 binary as Command Line Tool in PHPStorm 6 by infomaniac

Comments are closed.