A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.jetbrains.com/help/phpstorm/using-the-composer-dependency-manager.html below:

Composer dependency manager | PhpStorm Documentation

Composer dependency manager

PhpStorm integrates with the Composer dependency manager, which allows you to declare packages from Packagist or a custom repository as your project's dependencies and manage them from the IDE. PhpStorm provides:

Download and install Composer

For more information about installing Composer, refer to the Composer official documentation.

If you work in a local environment, Composer commands in PhpStorm are run via the configured local PHP interpreter. You can download and install Composer manually as a system-wide standalone tool, or have PhpStorm download it automatically when you create a new Composer project, initialize Composer, or invoke other Composer commands in an existing project.

Additionally, PhpStorm enables you run Composer commands via any configured remote PHP interpreter.

Set up Composer commands execution

  1. Open the Composer dialog by either of the following:

  2. Choose how the Composer commands will be executed:

Set up a project with Composer

In PhpStorm, you can work with existing Composer projects, create new projects based on the Composer package of your choice, or initialize Composer in an existing project. PhpStorm resolves dependencies and uses the information from composer.json to automatically apply certain configuration options.

Open a Composer-managed project in PhpStorm

When you open an existing Composer-managed project, PhpStorm uses the information contained in the composer.json file to automatically apply the project's content roots and PHP language level.

  1. Click Open on the Welcome screen or go to in the main menu, then choose the folder where your Composer project is stored.

    PhpStorm opens the project and shows a notification:

  2. Click to open the Composer dialog and configure the project settings if required:

    Click OK to apply the specified project settings and close the dialog.

  3. Install project dependencies from composer.json by one of the following:

    If your PhpStorm project has an invalid PHP interpreter version or is missing a PHP extension or library, PhpStorm will prompt you to run Composer install with the --ignore-platform-reqs option.

    The third-party libraries declared as dependencies in composer.json are installed in the vendor directory inside your project.

    By default, folders in the vendor directory are Excluded, but added to the project via PHP include paths. Such folders are marked as library roots by PhpStorm. Unlike other Excluded directories, library directories are indexed and therefore subject to the related IDE features such as code completion or refactoring. At the same time, libraries are protected with a warning popup upon every modification attempt, be it direct intentional editing or update result from refactoring.

Create a project from Composer package

When you create a new Composer project, PhpStorm creates a project based on the Composer package of your choice, resolves the dependencies and installs them under the project's vendor directory.

Creating a project is possible only when Composer is run via the configured local PHP interpreter.

  1. Choose or click Create New Project on the PhpStorm Welcome screen.

    The New Project dialog opens:

  2. In the dialog, specify the project's parameters:

    1. Select the project type and location:

      • In the left-hand pane, select Composer Package Project.

      • In the Location field on the right-hand pane, specify the folder where the project will be created.

    2. Choose how the Composer commands will be executed:

      • To run commands via a globally installed composer executable, choose 'composer' executable and specify its location in the field.

      • To run commands via the local composer.phar archive, choose composer.phar. Then, either specify the location of the existing composer.phar file in the field or select the Download composer.phar from getcomposer.org checkbox to download a new instance of the file. The downloaded composer.phar file will be saved under the project root folder.

        Then, choose one of the configured local PHP interpreters from the PHP interpreter list. For more information, refer to Configure local PHP interpreters.

      Optionally, in the Command line parameters field, type the additional command line parameters.

    3. In the Package area, type the name of the desired package in the Package field. To use code completion, press Ctrl+Space. Then choose the relevant version from the Version to install list.

  3. Click Create. The create-project Composer command will be invoked with the selected package. As a result, a Composer project whose configuration and structure depend on the selected package will be created and opened.

Initialize Composer in an existing project

When you initialize Composer in a project, a composer.json file is created. This file lists the project dependencies and other metadata and is automatically set as the project's default Composer file.

  1. Go to .

    The Composer Settings dialog opens:

  2. Choose how the Composer commands will be executed:

  3. Click OK to close the Composer Settings dialog. PhpStorm creates a composer.json stub file and opens it in the editor:

    Complete the code or accept the generated values. For more information about working with the composer.json file, refer to Composer.json: Project Setup.

Manage multiple composer.json files

You can have several composer.json files in one PhpStorm project, and invoke Composer actions and commands for each of them.

If a project contains subdirectories with dedicated composer.json files, PhpStorm handles Composer-managed dependencies and settings for each of such modules independently. Every subdirectory with composer.json installed in it will have its own PSR-0/PSR-4 roots settings, configurations for test frameworks, and a vendor directory with External Libraries.

To manage composer.json files in your project:

Work with composer.json

The composer.json file describes the dependencies of your project and may also contain other metadata. PhpStorm provides comprehensive coding assistance for working with composer.json and lets you perform many Composer-related tasks directly from the code editor.

Use the shortcut links on top of the composer.json editor panel to quickly install or update the project dependencies, open the Composer Log, and access additional commands.

If necessary, you can disable the shortcuts panel. In the Settings dialog (Ctrl+Alt+S) , go to and clear the Show composer.json top panel with quick actions checkbox.

Create a composer.json file

You can create composer.json files manually. If Composer hasn't yet been initialized in the project, a newly created composer.json will be automatically set as the project's main Composer file.

  1. Do one of the following:

  2. In the popup menu, select composer.json File. PhpStorm creates a stub of the composer.json file and opens it in the editor.

The composer.json file is created with default content. If necessary, you can customize the corresponding composer.json file template on the page of the Settings dialog (Ctrl+Alt+S) . For more information, refer to File templates.

Use code completion in composer.json Use quick documentation in composer.json Navigate from a composer.json record to the project entity or setting Manage dependencies

To install, update, or uninstall project dependencies, you need to update the records in the require or require-dev sections in composer.json and then run the corresponding Composer command.

To retrieve the available package updates and provide better coding assistance in composer.json, PhpStorm runs the update --dry-run command in the background every time you open a project or modify composer.json. If necessary, you can disable running the command. In the Settings dialog (Ctrl+Alt+S) , go to and clear the Check for available package updates checkbox.

When you open a project or modify composer.json, PhpStorm checks whether the vendor directory is present. If it is missing, PhpStorm displays the notification message.

Click the Run 'composer install' shortcut link in the notification message to quickly install the project dependencies. If necessary, you can disable this notifcation by clearing the Notify about missing 'vendor' directory checkbox on the page of the Settings dialog (Ctrl+Alt+S) .

Install dependencies
  1. Inside composer.json, add the desired dependency record to the require or require-dev section. Press Ctrl+Space to get code completion both for the package name and version.

    When specifying the package version, you can provide version constrains, too, for example >=1.0 <2.0. For more information, refer to the Composer official documentation.

  2. Do one of the following:

When a new package is installed, PhpStorm creates a new subfolder under vendor and stores the package inside. If the composer.lock file is present in the current directory, the exact packages versions listed in it are installed. Otherwise, if the composer.lock file is missing, Composer will create it after installing the packages, thus locking your project to their specific versions.

Learn more about adding dependencies on the Composer Official website.

Update dependencies

You can update packages to their latest versions individually, or update all the packages listed in the require and require-dev sections of composer.json at once.

Learn more about updating dependencies on the Composer Official Website

Install/update dependencies with options

When installing or updating dependencies, PhpStorm can run the respective Composer commands with the --ignore-platform-reqs option.

The --ignore-platform-reqs option enables installation or update of dependencies even if your PhpStorm project has an invalid PHP interpreter version or is missing a PHP extension or library.

To run the install/update commands with an option, configure Composer in PhpStorm settings:

Uninstall dependencies
  1. Remove the package record from the require or require-dev section of composer.json.

  2. Click the Update shortcut link on top of the composer.json editor panel.

Use a custom package repository

Besides Packagist, you can use a custom package repository.

For more information about setting up your own package repository, refer to the Composer official documentation.

Create and run Composer scripts

With Composer, you can create and run scripts, which are used for executing some custom code or package-specific commands during the Composer execution process.

Define a Composer script Rename a Composer script
  1. Place the caret at a script's definition or usage.

  2. Invoke the Rename refactoring by selecting from the main menu or from the context menu, or press Shift+F6.

  3. In the Rename dialog that opens, provide the desired name for a script.

  4. Click Preview to observe possible changes in the Find tool window. Click Refactor to proceed.

Run a composer script

When the script is executed, PhpStorm automatically creates a dedicated temporary Composer Script run/debug configuration for it. You can save it as a permanent run/debug configuration if necessary.

Create a Composer script run/debug configuration

You can execute Composer scripts by using run configurations of the Composer Script type. With the run configuration, you can execute a script at any point, add it to the Services tool window, or a compound configuration. For more information about Working with Run/Debug Configurations.

  1. Do any of the following:

  2. Provide the run/debug configuration parameters:

Save a temporary Composer Script run/debug configuration

When you execute a Composer script from the editor, PhpStorm automatically creates a temporary run/debug configuration with the script parameters. A temporary run/debug configuration works the same way as a permanent run/debug configuration. You can change its settings using the Run/Debug Configuration dialog and optionally save it as permanent.

Execute a Composer script using a run/debug configuration View the Composer log

When you execute a Composer-related command via the PhpStorm interface, the command's output is displayed in the dedicated Composer Log console:

Click the composer.json link in the log to open the file in the editor.

Open Composer log View the folded Composer Log message

If a Composer command has been executed successfully, Composer Log will fold its execution details.

To re-run a command, click in the gutter.

When appointing the main composer.json file in a project, you can enable PhpStorm's settings synchronization with it. Composer Log will highlight such a change in the settings as it occurs. Click in the gutter to quickly navigate to the corresponding Directories, PHP, Test Frameworks, or PHP command line tools settings pages.

Run additional Composer commands

PhpStorm provides the user interface for a set of additional Composer commands.

For more information about all Composer commands, refer to the Composer documentation.

If Composer execution is not set up, the Composer Settings dialog will open, prompting you to choose how the Composer commands will be executed:

Validate

Run this command to perform several validity checks against the composer.json file, which is recommended before committing composer.json to a VCS. Validation results are displayed in the Composer Log console.

The equivalent Composer CLI command is validate.

Before executing the command, choose the desired options in the Validation Settings dialog:

Dump Autoloader

Run this command to generate the list of autoloaded classes. If the list already exists, it will be generated anew. This can be useful in situations when you introduce a new class in a project and need to include it to the list of autoloaded classes. For more information about autoloading classes with Composer, refer to the Composer documentation.

The equivalent Composer CLI command is dump-autoload.

Before executing the command, choose the desired options in the Autoloader Generation Settings dialog:

For more information about the general autoloader optimization strategies, refer to the Autoloader Optimization.

Check for Changes in Dependencies

Run this command to check if you have any local changes in the code of the package dependencies.

The equivalent Composer CLI command is status.

Clear Cache

Run this command to delete the Composer's cache directory, which contains the downloaded packages. By default, the cache directory is set to C:\Users\<user>\AppData\Local\Composer on Windows, and to ~/.composer/cache on Linux and macOS. For more information, refer to Composer documentation.

The equivalent Composer CLI command is clear-cache.

List Licenses

Run this command to view the name, version, and license type of every installed package.

The equivalent Composer CLI command is licenses.

Diagnose

Run this command to perform automated checks for the most common Composer problems (for example, connectivity issues, Composer/PHP version used, disk space available, composer.json validity). If the problem is not identified, refer to the Composer troubleshooting guide.

The equivalent Composer CLI command is diagnose.

Simulate Update

Run this command to simulate updating the dependencies without actually running composer update. In doing so, you can verify whether all dependencies are resolved successfully and preview the changes while keeping everything intact.

The equivalent Composer CLI command is update --dry-run.

To retrieve the available package updates and provide better coding assistance in composer.json, PhpStorm runs the update --dry-run command in the background every time you open a project or modify composer.json. If necessary, you can disable running the command. In the Settings dialog (Ctrl+Alt+S) , go to and clear the Check for available package updates checkbox.

Self-Update

Run this command to update Composer itself (that is, the composer.phar file) to the latest version.

The equivalent Composer CLI command is self-update.

Run Composer from the command line

Command-line mode provides you with the full range of Composer commands. To use Composer in this mode, you need to configure it as an external command-line tool. For more information about working with command-line tools, refer to PHP command line tools.

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.

Configure Composer as a command line tool
  1. In the Settings dialog (Ctrl+Alt+S) , go to .

  2. Click on the toolbar.

  3. In the Command Line Tools dialog, choose Composer from the list, and specify its visibility level (Project or Global).

  4. When you click OK, the dialog opens.

    Specify how you want to launch Composer by choosing one of the options: composer.phar or php script or composer executable. Depending on your choice, specify the paths to the PHP installation folder and composer.phar or to the composer executable file.

    PhpStorm parses the contents of the specified .phar archive or executable file for Composer commands. When the file analysis is completed, PhpStorm returns to the PHP Command Line Tool Support page where the specified file is added to the list of command line tools available in PhpStorm.

  5. Click OK to apply changes and return to the PHP Command Line Tool Support page. Optionally, click to edit the tool properties, or to customize the commands set. For more information, refer to Customize a tool.

Run a Composer command Terminate a command

11 October 2024


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4