PhpStorm 2019.2 Help

Symfony

PhpStorm provides coding assistance and navigation facilities for developing applications with the Symfony framework.

Symfony support is provided by means of the Symfony Plugin. The source code for the plugin, as well as its issue tracker, can be found on GitHub.

Before you start

Before you start working with Symfony, make sure that the Symfony and PHP Annotations plugins are installed and enabled.

Enabling the Symfony Plugin for a project

Having installed the Symfony plugin, you need to explicitly enable it for the project. After creating or opening a Symfony project, PhpStorm will display a notification message suggesting you enable the plugin.

Enable the Symfony Plugin for a project

  1. Do any of the following:

    • Click the Enable the Symfony plugin with autoconfiguration link in the notification message.

      Symfony plugin notification
    • In the Settings/Preferences dialog (Ctrl+Alt+S), navigate to Languages & Frameworks | PHP | Symfony and select the Enable Plugin for this Project checkbox.

  2. Restart PhpStorm for the changes to take effect.

Specifying additional settings

Depending on how the Symfony project is structured, you may have to change some additional settings under Languages & Frameworks | PHP | Symfony. When working with a Symfony application that follows the structure generated by, for example, the symfony/framework-standard-edition Composer project, the default paths and settings will work fine.

Note that the appDevDebugProjectContainer.xml and appDevUrlGenerator.php must be located under the Symfony's default path in order to work with all features the Symfony Plugin provides. It will use a fallback mechanism when these files cannot be found, but completion and navigation will be less precise in this case.

When using a non-default project structure, the following paths should be updated in the Symfony Plugin settings:

  • Translation Root Path: the path to the location where all translations are copied. This should be set to the translations path under the cache folder, so that all possible translations are discovered by the plugin.

  • App Directory: the path to the app directory.

  • Web Directory: the path to the web directory.

Symfony general settings

Symfony profiler

When the Symfony Plugin is enabled for a project, an additional region will be added to the PhpStorm status bar. Clicking Symfony in the status bar will open the popup menu with the related targets for the latest requests being made to our Symfony application.

Symfony profiler toolbar

Navigate to a related target

  • Click the corresponding item in the profiler popup menu:

    • Debug URL: the Symfony profiler URL for the given request, for example, /app_dev.php/_profiler/355651.

    • Routes: the route registration in the application

    • Controller: the controller that was involved in creating a response.

    • Template: any of the templates related to a response.

Symfony Code Style

PhpStorm provides the built-in Symfony2 code style tailored for Symfony development.

Set the Symfony2 code style

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), navigate to Editor | Code Style |PHP.

  2. Click the Set from... link in the upper-right corner and select the Predefined Style | Symfony2 option from the popup menu.

    Symfony code style settings

Checking code against the Symfony coding standards

With PhpStorm, you can use the PHP Code Sniffer tool, which detects coding standard issues, in combination with Symfony coding standard, which provides a set of Symfony-specific standards to PHP Code Sniffer. This will ensure that your code is clean, consistent, and free of some common errors.

To get started, install PHP Code Sniffer using any technique described in Installing and configuring PHP Code Sniffer. Probably the easiest way is to install it with Composer.

Install PHP Code Sniffer

  1. From the context menu of composer.json, choose Composer | Manage Dependencies. Alternatively choose Tools | Composer | Manage Dependencies from the main menu.

  2. In the Manage Composer Dependencies Dialog that opens, select the squizlabs/php_codesniffer package from the Available Packages list, possibly using the search field.

    Choose the relevant version from the Version to install list.

  3. If necessary, expand the Settings hidden area and specify the advanced installation options. In the Command line parameters field, type the additional command line parameters.

  4. Click Install.

Next, install Symfony coding standard, which will provide Symfony-specific standards to PHP Code Sniffer.

Install Symfony coding standard

  1. From the context menu of composer.json, choose Composer | Manage Dependencies. Alternatively choose Tools | Composer | Manage Dependencies from the main menu.

  2. In the Manage Composer Dependencies Dialog that opens, select the escapestudios/symfony2-coding-standard package from the Available Packages list, possibly using the search field.

    Choose the relevant version from the Version to install list.

  3. If necessary, expand the Settings hidden area and specify the advanced installation options. In the Command line parameters field, type the additional command line parameters.

  4. Click Install.

The Symfony coding standard package will be installed, and the corresponding Symfony standard will be selected for the PHP Code Sniffer validation inspection automatically. If necessary, you can further customize the inspection on the Editor | Inspections page of the Settings/Preferences dialog (Ctrl+Alt+S). See Configuring PHP Code Sniffer as a PhpStorm inspection for details.

Using the Symfony command line tool from PhpStorm

PhpStorm integrates with the Symfony console and scripting interface. Before you begin, download and install Symfony Console as described at https://symfony.com/doc/current/components/console.html.

Configure Symfony as a command line tool

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Tools | Command Line Tool Support.

  2. Click the Add button on the toolbar.

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

    the Command Line Tools dialog
  4. When you click OK, the Symfony dialog opens.

    Provide the path to the Symfony console executable file and the PHP interpreter, set the Symfony version, and click OK.

    The default executable location is <Symfony-home>/data/bin/symfony for Symfony 1.*, <Symfony-home>/app/console for Symfony 2, and <Symfony-home>/bin/console for Symfony 3 and later.

  5. Click OK to apply changes and return to the Command Line Tool Support page. Optionally, click the Edit button to edit the tool properties, or the Edit Source button to customize the commands set. See Customizing a tool for details.

Run Symfony commands

  • From the main menu, choose Tools | Run Command or press Ctrl twice.

    In the Run Anything window that opens, type the call of the command in the <s> <command> format.

    The command execution result is displayed in the Run Tool Window.

Terminate a command

Last modified: 23 August 2019