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

About Gary Hockin

Gary Hockin has been creating code to power web applications for 15 years, the last three of them at an extraordinary level. He is handsome, talented, funny and articulate, and also extremely modest. Gary is a valued contributor to Zend Framework 2 and is a member of the community review team. He's married and has two wonderful children, and when he's not coding, writing about code, speaking about code or reading about code, he can usually be found in the pub playing pool.
This entry was posted in Cool Feature, Newsletter and tagged , . Bookmark the permalink.
  • Philippe Villiers

    Does this feature still needs for a composer.phar file to be in the project folder?

    • Vladimir Luchansky

      No, it doesn’t. You can set the path to phar or executable in SettingsPreferences | Languages & Frameworks | PHP | Composer and it was like this in previous versions too.

      • Philippe Villiers

        Ok thanks !

  • J7mbo

    Does this feature work with remote interpreters, like a docker one?

    • Vladimir Luchansky
      • J7mbo

        Nice, thanks! In the future, could new features take into consideration remote interpreters by default? It’s sad to see new features coming out, but have to wait another month to actually use them (almost everyone here uses remote interpreters).

        • Eugene Morozov

          Unfortunately, it’s not that easy, if it was we’d already implemented it.

        • Vladimir Luchansky

          We’ll check on what can be done here, thanks! :)

  • Kevin Borchers

    How do I MAKE THIS GO AWAY????? It is the most annoying thing you guys have ever put into PHPStorm (and given how annoying it’s become, that’s saying something.) It’s fine if people can use, but since you’ve completely borked the ability to integrate with vagrant on the Macintosh, it’s useless to me. But no, I can’t dismiss it.

    My renewal is in January. The way you guys have screwed up–and continually ignore how the program works in Macs–I think this will be my last year of using PHPStorm. It’s a shame, because I really used to like it. Now I spend far too much time begging it to stop “helping” me.

    • Kevin Borchers

      Also? Whoever the idiot was who decided it should ask to install from EVERY package.json file it finds in vendor needs to be taken out back and hurt. A lot. A new project can have DOZENS of package.json files and on opening up, it often freezes for minutes (literally “minutes”) so it can pop up requests to install dependencies FROM EVERY FREAKING package file. I have to wonder who is so stupid not to consider how painful that is.

    • Eugene Morozov

      No such a way currently. Please vote: https://youtrack.jetbrains.com/issue/WI-37611