PhpStorm 2019.2 Help

Tutorial: integrating the Yii command line tool with PhpStorm

In PhpStorm, you can run commands of several third-party command-line tools as well as define your own ones. As an example, let's integrate the Yii command line tool with PhpStorm.

  1. Create a new Composer project and choose to install the yiisoft/yii2-app-basic package.

    The New Project wizard
  2. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Tools | Command Line Tool Support.

  3. Click the Add button on the toolbar. In the Command Line Tools dialog, select Custom tool from the Choose tool list and set its visibility level to project.

    the Command Line Tools dialog
  4. Click OK. In the Tool Settings dialog, provide the tool's main parameters. In our case, the tool is located under the project root, and we use the yii alias for it.

    the Tool Settings dialog
  5. Apply the changes and close the Settings/Preferences dialog. The tool xml definition will open in the editor.

    Custom yii tool initial definition
  6. To use code completion for yii commands, we need to define them first in the xml tool descriptor.

    A command's definition is organized as follows:

    <command> <!--the command's container--> <name> <!--the command itself, mandatory, and non-empty--> </name> <help> <!--the command's help message, optional--> </help> <params> <!--the command's parameters and their default values--> </params> <optionsBefore> <!--the command's options container--> <option name="" shortcut=""> <!--the option itself, mandatory, and non-empty; you can also provide a shorthand abbreviation and the usage pattern via attributes--> <help> <!--the command's help message, optional--> </help> </option> </optionsBefore> </command>

    Let's add a definition for a simple hello command, which echoes the entered argument. The command is executed via the following syntax:

    yii hello [message] [...options...]

    The resulting definition for this command should look as follows:

    <command> <name>hello</name> <help>Echoes the entered argument</help> <params>message</params> <optionsBefore> <option name="--appconfig"> <help> Custom application configuration file path. If not set, default application configuration is used. </help> </option> <option name="--color" pattern="equals"> <help> Boolean, 0 or 1. Enables or disables ANSI color in the output. If not set, ANSI color will only be enabled for terminals that support it. </help> </option> <option name="--help" shortcut="-h" pattern="equals"> <help> Boolean, 0 or 1. Defines whether to display help information about current command. </help> </option> <option name="--interactive" pattern="equals"> <help> Boolean, 0 or 1. Defines whether to run the command interactively. </help> </option> </optionsBefore> </command>
  7. The basic tool definition is ready. Select Tools | Run Command form the main menu, or press Ctrl twice. In the Run Anything window that opens, type a command and press Enter.

You can find the full yii tool definition file in the yii2-phpstorm-commandlinetool GitHub repository. Have a look at other notable examples, too!

Last modified: 23 September 2019