Features Releases

New Composer Update in PhpStorm 2017.2

Composer is the cornerstone of modern PHP development, and we’ve made some improvements in PhpStorm 2017.2 to help you work with Composer from within the IDE.

In a recent post, we described how configuring Composer correctly in PhpStorm 2017.2 can help with automatically configuring the rest of your IDE settings (you tell PhpStorm where to find your Composer executable and `composer.json` file). Once you have Composer configured you’ll be able to use the built-in Composer actions.

You can invoke these action from multiple places; you can find the Install, Update and Manage dependencies… actions in the context menu (right click) when highlighting a `composer.json` file in the project window, or in the context menu for an opened `composer.json` file. There are also Install and Update buttons on the top of a `composer.json` file that’s open in the editor; it’s useful to invoke these action from the specific `composer.json` file when you have multiple configuration files in your project and you need to only work with the dependencies from one of those files.  You can find all the actions including Init Composer… and Self-update in the Tools | Composer toolbar.

composer-tools-menu

 

We’ll cover Manage dependencies… first as it’s not a new feature in 2017.2, but has had improvements. It lets you manage Composer dependencies from a window. You can search for packages, check that it’s the right package and select a version to install from the window without needing to remember the command line parameters. There’s something new in the dependencies window; you can now Remove dependencies as well as install them.

composer-add-dependency

New in PhpStorm 2017.2, you can now run even more actions with Composer. Self-update will attempt to make sure you’re running the most recent Composer version by running the `composer self-update` command.

Install will run a `composer install` command. This pulls down the versions of the dependencies that are in the project’s `composer.lock` file – the last versions that were resolved from an update. This is very useful if a project ships with a lock file and you want to get the exact dependencies that are listed there.

Update runs a `composer update`. Update is different to install because it will pull down newer versions of dependencies if they exist and can satisfy the criteria. For example, you may define Monolog needs to be `”>1.22.0″` (any version later than 1.22.0). If version 1.23.0 has been released since you last did an update, this will be downloaded and the `composer.lock` file will reflect this new version.

Install, Update and Manage dependencies all require a `composer.json` file to be either selected or configured in the Composer configuration of PhpStorm, whereas Self-update only requires that you have a Composer executable configured.

If like me, you have Composer installed globally then you can configure PhpStorm once and have all your future projects already know where Composer is installed. The easiest way to do this is from the File | Default Settings… menu, then under Languages & Frameworks | PHP | Composer.

We’re looking to improve Composer support in upcoming versions of PhpStorm and would be interested to hear how you think we can help you use Composer more efficiently from within PhpStorm.

– Gary & The PhpStorm Team

image description