Working with Composer

This topic describes how to work with Composer in Zend Studio.

Creating a New Project with Composer Support

Composer support can be added when you create a new PHP project by using the Empty Composer Project wizard.

 

 

Instructions on how to complete a procedure

To add Composer support during project creation:

  1. In the menu-bar, select File | New | Empty Composer Project.
    A New Composer Project wizard is displayed.

  1. Enter project name and vendor name. Other fields are optional.
  2. Click Next.

  1. Adjust the PSR-4 namespace if necessary.
  2. Click Finish to complete the wizard.
    The new project is created and is displayed in the Project Explorer.
    The composer.json file is opened in the Composer Editor.


You can now install library dependencies in your project. See Adding and Installing Dependencies below for more information.

Creating a New Project from Existing Composer Package

New Composer projects can be created from existing Composer packages, published on Packagist, as if they have been created using the "composer create-project" command.

 

 

Instructions on how to complete a procedure

To create new project from Composer package:

  1. In the menu-bar, select File | New | PHP Project from Composer Package.
    A new project wizard is displayed.

  1. Enter project name. Other fields are optional.
  2. Click Next.
    The Select Package page is displayed.

  1. Enter a search query in the Find text field.
    A list of available packages is displayed.
  2. Click Select next to the package you want to create the project from.
  3. Select the desired version of the package from the drop-down list.
  4. Click Finish to complete the wizard.
    The new project is created and is displayed in the Project Explorer.
    The composer.json file is opened in the Composer Editor.
    The progress of installing the required dependencies is displayed in the Console view.


Adding Composer Support to an Existing Project

Composer support is added per PHP project. This procedure describes how to add Composer support to a project.

 

 

Instructions on how to complete a procedure

To add Composer support:

In the PHP Explorer, right-click your PHP project and select Configure | Add Composer Support.

Zend Studio adds Composer support to your PHP project, and displays the Composer editor.

You can now install library dependencies in your project. See Adding and Installing Dependencies below for more information.

Adding and Installing Dependencies

This procedure explains how to add and install library dependencies in your PHP project.

 

 

Instructions on how to complete a procedure

To add and install a dependency:

  1. In the Project Explorer, select the 'composer.json' file (displayed automatically after adding Composer support).

  1. Click on the Dependencies tab at the bottom of the editor.
    The Dependencies page is displayed.

  1. By default new dependencies are added to the Require section. If you want to add a require-dev dependency then expand the Require (Development) section.
  2. Begin entering the name of the package in the Packagist Search section.
    Zend Studio searches for packages and displays a list of the available corresponding packages.

  1. Select one or more packages from the list.

  1. Define the version rule for the dependency (e.g., Minor: ~1.2).

  1. Click Add Dependencies.
    The dependency is added to the list of project dependencies in the Composer editor.

  1. Save your project.
  2. To install the dependency, click the Install dependencies button in the editor's toolbar. Composer will install the package. You can view the progress of the installation in the Console view.
  3. To configure a dependency, select it from the list of project dependencies, and click Modify. To delete it, click Remove.

Note:

Once your first dependency is installed, you can update the packages by clicking the Update dependencies button in the editor's toolbar. This action will also install any other dependencies you may have added.

Configuring Composer

This procedure describes how to configure preferences for the Composer.

 

 

Instructions on how to complete a procedure

To configure Composer:

  1. In the menu-bar, go to Window | Preferences | PHP | Composer.
    The Composer preferences page is displayed.

  1. Click the PHP executable drop-down menu to select the PHP executable to use when executing Composer commands. Click PHP Executables hyperlink to add an executable.

  2. In the Composer binary section, define which 'composer.phar' file to use.
  1. Click Apply to save changes, and OK to exit Preferences.