IntelliJ IDEA 14.0.0 Web Help

Using Composer Dependency Manager

The Composer Dependency Manager is very helpful when you need to install PHP-related frameworks, for example PHPUnit or Behat test frameworks.

You can use Composer from IntelliJ IDEA in three modes:

  • Using the dedicated IntelliJ IDEA interface for most basic operations such as initializing a project with a composer.json stub created and adding dependencies.
  • To have all Composer commands at disposal, you need to configure Composer as a command line tool and use it in the command line mode from the dedicated Command Line Tools Console Tool Window or pop-up window. For more details, see Running Command Line Tool Commands.
  • You can have IntelliJ IDEA generate a project stub from an existing package using Composer. In this case, Composer will be initialized and one package will be installed during the project stub creation. After that you can use Composer from the command line or through the user interface.

On this page:

Preparing to run Composer in the command line mode

  1. Download the Composer.phar definition file.
  2. Make sure the Command Line Tool Support plugin is installed and enabled.

    The plugin is not bundled with IntelliJ IDEA, but it is available from the JetBrains plugin repository. Once enabled, the plugin is available at the IDE level, that is, you can use it in all your IntelliJ IDEA projects. See Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins for details.

  3. Open the project settings by choosing File | Settings | Project Settings . Then click Command Line Tool Support.
  4. On the Command Line Tool Support page, click the Add button. In the Choose Tool to Add dialog box that opens, choose Composer.
  5. In the Composer dialog box that opens, choose the way to launch Composer:
    • Composer.phar or php script: Choose this option to launch Composer through a PHP script or have IntelliJ IDEA detect and start the launcher in the composer.phar archive. In this mode, IntelliJ IDEA provides coding assistance and allows to execute scripts.

      In the Path to PHP executable field, specify the location of the PHP engine installation folder. Choose the PHP installation from the list, or type the path manually, or click the Browse button browseButton.png and choose the desired location in the dialog box that opens.

      In the Path to composer.phar or composer text box, specify the location of the composer.phar archive. Type the path manually or click the Browse button browseButton.png and choose the desired location in the dialog box that opens.

    • Composer executable: choose this option to launch Composer through the Composer executable file. In this mode, you do not get coding assistance and cannot execute scripts because not PHP engine is appointed for it.

      In the Path to executable text box, specify the location of the composer executable file. Type the path manually or click the Browse button browseButton.png and choose the desired location in the dialog box that opens.

    IntelliJ IDEA parses the contents of the specified .phar archive or executable file for Composer commands. When the file analyses is completed, IntelliJ IDEA returns to the Command Line Tools page of the Settings dialog bos where the specified file is added to the list of command line tools available in IntelliJ IDEA.

    You can have several instances of Composer configured and switch between them from one project to another by specifying the relevant one during Composer initialization.

  6. In the Alias text box, specify the alias to use in calls of tool commands when running in the command line mode. Accept the default alias c or edit it, if necessary.
  7. To activate the detected command set, select the Enable check box.
  8. Customize the command set, if necessary.
  9. In the Show console in area, specify where you want the Input pane for typing commands opened:
    • To have the Input pane opened in a pop-up window, choose the Pop-up option.
    • To have the Input pane opened as a text box at the bottom of the Command Line Tools Console tool window, choose the Tool window option.

Using Composer via the dedicated user interface

IntelliJ IDEA provides a dedicated interface for such basic Composer operations as initializing a project and adding dependencies. In the UI mode, Composer is available at the project level. For information on using the tool from the command line, see Running Command Line Tool Commands.

Setting up Composer in an existing project

  1. Open the project to use Composer.
  2. Open the Settings dialog box ( File | Settings ), then under the PHP node click Composer.
  3. On the Composer that opens, specify the following:
    1. In the Path to PHP executable field, specify the location of the PHP engine installation folder. Choose the PHP installation from the list, or type the path manually, or click the Browse button browseButton.png and choose the desired location in the dialog box that opens.
    2. In the Path to composer.phar text box, specify the location of the composer.phar archive. Type the path manually or click the Browse button browseButton.png and choose the desired location in the dialog box that opens.
    3. If you have not downloaded the composer.phar file yet, click the Download link to have IntelliJ IDEA download composer.phar from the official storage and specify the folder to store the archive in. This instance of Composer will be available in the current project only. To use it in the command line mode, configure it as a command line tool.
    4. Specify how you want IntelliJ IDEA to treat Composer packages:
      • To have IntelliJ IDEA mark Composer packages added to the current project as libraries., select the Add packages as libraries check box.

        In the context of IntelliJ IDEA, any file marked as library is automatically write-protected. Library files are indexed for the only purpose which is enhancing coding assistance (i.e. code completion, syntax highlighting, navigation, and documentation lookup). Library files are not to be edited in the scope of the project where they are declared as library.

        By default, the Add packages as libraries check box is selected, which automatically blocks the possibility to edit them in the current project.

      • If you want to use Composer packages in your development and at the same time update them yourself within the scope of the same project, clear the Add packages as libraries check box.
  4. Click OK to save the Composer settings and leave the Settings dialog box.
  5. On the main menu, choose Tools | Composer | Init Composer . IntelliJ IDEA creates a stub of the composer.json file and opens it in the editor.
  6. Complete the code or accept the default values. For more details, see Composer.json: Project Setup.

Quick Composer set-up

  1. On the main menu, choose Tools | Composer | Init Composer .
  2. In the Composer Settings dialog that opens, specify the location of the composer.phar archive and the PHP engine to use. If you have not downloaded the composer.phar file yet, click the Download link to have IntelliJ IDEA download it now and specify the folder to store the file in.
  3. Click OK. The dialog box is closed whereupon IntelliJ IDEA creates a stub of the composer.json file and opens it in the editor.
  4. Complete the code or accept the default values. For more details, see Composer.json: Project Setup.

Adding Composer dependencies

  1. Open the project where Composer is set up and choose Tools | Composer | Add Dependency on the main menu.
  2. In the Add Composer Dependency dialog that opens, select the packageToAdd from the Available Packages list, possibly using the search field. The list shows all the available packages, however, the packages that have been already installed are marked with a tick.

    Choose the relevant version from the Version to install drop-down list.

  3. If necessary, expand the Settings hidden area and specify the advanced installation options. In the Command line parameters text box, type the additional command line parameters to adjust the add dependency procedure. For example, to have a dependency added to the require-dev section instead of the default require section type -dev. For more information about Composer command line options during installation, see https://getcomposer.org/doc/03-cli.md.
  4. Click Install.

Generating a Composer project stub

  1. Choose File | New Project on the main menu or click the New Project button on the Welcome screen.
  2. In the Create New Project dialog box that opens, specify the project name and location.
  3. From the Project type drop-down list, choose Composer Project. The Composer Project Dialog opens.
  4. Appoint the Composer instance to use.
    • To use commands from a previously downloaded composer.phar, choose Use existing composer.phar: and specify it location in the text box.
    • To have a new instance of Composer downloaded, choose Download composer.phar from getcomposer.org:. The composer.phar file will be saved under the project root folder specified in the Create New Project dialog.
  5. In the Package area, specify the package to install during the project creation. Select the package to add from the Available Packages list, possibly using the search field, and choose the relevant version from the Version to install drop-down list.

See Also

Last modified: 12 November 2014
comments powered by Disqus