Symfony Command Line Usage With Command Line Tool Support

Since PhpStorm 2.0 Symfony framework command line tool can be used inside PhpStorm by Command Line Tool Support.

Let’s pass through a simple Symfony tutorial, and then create a custom task. You’ll need having PhpStorm 2.0 and Symfony 1.1 or newer stable release installed on your computer. If you have no Symfony, tutorial describes its installation.

First we need to configure a new command line tool with Symfony commands.

Loading Symfony Commands

Choose Settings | Command Line Tool Support and press the “Add” button. Three options are offered. Choose “Symfony”:

Choose Symfony Framework To Add

Then provide the path to its $Symfony_home$/data/bin/symfony file. For configuration from tutorial, that path is $Project_root$/lib/vendor/symfony/data/bin/symfony. The description of Symfony commands is loaded and saved in a file inside your project settings. In the Settings dialog box, the description looks as follows:

Symfony description in Settings

  • The Tool Path field contains the common part of all framework commands. These common parts are “php  $path_to_symfony$ “ in Symfony or “$Zend_Framework_Tool_home$/bin/zf.bat” in Zend Framework Tool. $PhpExecutable$ is a macro, it changes to the php configured in the project settings when a Symfony command is executed, and $ProjectFileDir$ changes to the full path to the project. Macros make sharing settings between several IDE instances much more handy.
  • A common Tool Path can be annoyingly long, so we provide an Alias, which is a string to be used instead of the full Tool Path.
  • By selecting or clearing the “Enable” checkbox, you can easily have framework commands included or excluded from tool’s auto completion without deleting the description file. Now the Enable checkbox is selected, so symfony commands are provided in auto completion.
    Press Ctrl +Shift+X or choose Tools | Run Command… and type:Symfony commands list

Using Symfony Command Line

Now we’ll create a simple Symfony project as it is described in Symfony’s  “Getting  Started” document.

Creating a Symfony Project

Press Ctrl +Shift+X and type:

Generate project command

The command has two parameters:

  • Required “name”. We set it to macro $ProjectName$, which stands for the name of the PhpStorm project.
  • Optional “author”.

Before the command execution, the $ProjectName$ macro will be exploded to the actual project name, and the framework alias “s” will be changed to the Tool Path. In our case, it is “usr/bin/php /home/sfproject/lib/vendor/symfony/data/bin/symfony”.

Project files are created:

Toolwindow with generated project

Configuring Database

Now configure database through Doctrine with command “php symfony configure:database “mysql:host=localhost;dbname=dbname” root mYsEcret”

Configuring database command

Creating a Frontend Application

Let’s create a frontend application without escaping output, though it makes our application less secure. Press Ctrl +Shift+X and type:

Generate application command

Note that options after commands are also supported. In our case the –escaping-strategy=false option defines that output is not escaped.

Check commands output:

Commands output

Directory Structure Rights

Next step in tutorial is setting appropriate permissions on the cache/ and log/ directories.  This can also be made by Command Line Tool Support. It invokes unknown commands and even resolves macros there. But note that there might be no “chmod” command on Windows.

Chmod command

Check result:

Chmod and ls output in toolwindow

Now configure your web server as described in the tutorial  and run it.

Testing

Check that you  have access to the new application by opening a browser at url http://localhost:8080/index.php/, and then open currently created application in the development environment at http://localhost:8080/frontend_dev.php/

Your project is ready:

Project page

Adding custom task

Let’s create a simple “hello” task inside a Symfony project. We suppose that you have previously loaded and enabled Symfony commands and created a Symfony project.

  1. Press Ctrl+Shift+X and type:Generate task commandA new task class “helloTask” is created inside the lib/task directory.
  2. Open the helloTask class in the editor and make the  following simple changes to its “execute” function:HelloTask class execute function
  3. Open the Symfony description file: choose Settings |  Command Line Tool Support and press the “Open definition in editor” button.
  4. Add a new “hello” command description:Hello command description
    Command description :
    <command>
    <name>hello</name>
    <help>My first task with no parameters.</help>
    </command>
  5. To test the new command, type:
    Hello command
    The result of executing the command is shown in the Output console:Hello, invoker!

Troubleshooting

If you get any  troubles while editing description file  and auto completion does not offer you expected commands, open the Validation tab of Command Line Tools Console. This tab shows  info about problems with parsing description files:

Validation tab

You can also get information about the description format from schema file at .idea/commandlinetools/schemas/frameworkDescriptionVersion1.1.xsd. Its path is provided in the generated description file, and the editor validates the file against the schema automatically.

More about Command Line Tool Support in this tutorial.

This blog is permanently closed.

For up-to-date information please follow to corresponding WebStorm blog or PhpStorm blog.

 
This entry was posted in Cool Feature, PhpStorm and tagged , , , . Bookmark the permalink.

21 Responses to Symfony Command Line Usage With Command Line Tool Support

  1. Rafi says:

    Any tips on setting the xml with the “custom framework” option?

  2. Shaverdova Elena says:

    @Rafi they are in tutorial http://devnet.jetbrains.net/docs/DOC-1230

  3. Hamrath says:

    I just hope, that this will happen for CakePHP, too. ;-)

  4. Shaverdova Elena says:

    @Hamrath you may create custom description for this framework. As far as i can see, it has only five default commands.

  5. Oleg says:

    How can I use this command line support with symfony2? There’s no /data/bin/symfony file to point to.

  6. Shaverdova Elena says:

    @Oleg Integration with symfony2 will be available in next EAP.

  7. nresni says:

    Hi,

    Is it possible to have a history of commands with arguments or should retype it each time ?

    nresni

  8. Shaverdova Elena says:

    @nresni History of commands with arguments will be added in next EAP.

  9. nresni says:

    cool !!!

    thks

  10. cordoval says:

    I think sf2 already works, if one points it to app/console

  11. Alexander says:

    Yes, Symfony2 console command works well…
    Just point to /path/to/app/bin/console command and then use it Ctrl+Shift+X… )
    >s doctrine:generate:entities
    Thats all )

    But I’ve much more interesting question: how do I use the correct TWIG syntax highlighting ? Smarty syntax not so identical, even if we’ve to change {} symbols in settings.

    TWIG: {{ var.value }}… {% expression %} and so on… ?

    Sincerely, Alexander

  12. Shaverdova Elena says:

    @Alexander Please, make a request for Twig support here: http://youtrack.jetbrains.net/issues/WI Any description of what exactly support you want is appreciated.

  13. Mahamed says:

    hi, where can i find macro list, am looking for the current file dir macro or how can i make on .thank you :)

  14. Shaverdova Elena says:

    @Mahamed in commands current dir is denoted by point. But for purposes of ExternalTools you may use $FileDir$. Also you can see macros in Settings | External Tools | Add | Insert macro dialog.

  15. Nikolay Matveev says:

    @Alexander, Elena
    Feature request for support Twig templates is already exist – http://youtrack.jetbrains.net/issue/WI-2879
    Just vote for it!

  16. theraipper says:

    Hi!

    Is there any possibility to run a command on a remote server accessible via SCP out of PHPStorm?

  17. Shaverdova Elena says:

    @theraipper
    Hi!
    Currently commands are run only locally.

  18. marphi says:

    Hi, I created small bundle to generate custom description file for support Symfony2 console. This bundle list all available commands from app/console. It may be useful.

    http://github.com/marphi/PhpStormSupportBundle

  19. cordoval says:

    I wonder about sequential execution or chaining commands

    http://devnet.jetbrains.net/docs/DOC-1230#cf

  20. Shaverdova Elena says:

    @cordoval let’s discuss in youtrack http://youtrack.jetbrains.net/issue/WI-7137 .

  21. Shaverdova Elena says:

    @marphi The only difference between generated by PhpStorm commands and your bundle’s are parameters with “–”, right?

Comments are closed.