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.
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.
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.
Develop with pleasure!
– JetBrains Web IDE Team
Subscribe to Blog updates
Thanks, we've got you!
Qodana Clone Finder: Early Access Program
In December 2020, we announced the EAP for Qodana, which is rapidly evolving into a comprehensive platform that allows companies to perform multi-level evaluations of the quality of code they own, contract, or purchase. Qodana helps you detect bugs without relying on an IDE, either on a local machi…
PhpStorm 2020.2 EAP #3
The Early Access Program for PhpStorm 2020.2 is in full swing and today we’ve got the third build of the 2020.2 EAP for you. In this blog post, you can read about improvements for Git installed in WSL2 and Search Everywhere. Download PhpStorm 2020.2 EAP (more…)…
PhpStorm 2019.3.3 Preview
We’ve just rolled out a preview for the third minor update for PhpStorm 2019.3. Please give the PhpStorm 2019.3.3 Preview build 193.6494.5 a try and share your feedback with us. (more…)…
How to Upgrade to PHP 7.4 with PhpStorm
Check out our fresh video with a few nice tips and tricks on how to update your codebase to PHP 7.4. It combines materials from the PhpStorm 2019.2 and PhpStorm 2019.3 releases, with a few cool bonuses to boot. Nikita drew our attention to the fact that setters are slower than assigning prop…