How to build a great Eclipse-Environment for Symfony2-Development

7. November 2011 in IDE, Symfony2

As I wrote in my last blog post, I was surprised about how good Eclipse fits for the development of Symfony2 projects. Long years I have avoided to work with Eclipse if possible. The reason was that the plain IDE was useless for PHP development. Without a lot of plugins the feature set can’t stand the comparison with the other major IDEs (especially PHPStorm). But there are a lot of plugins, a combination of them let you build a really good Symfony2-Development environment.

So lets take a look what I did. As always I would love to hear your comments on everything that could be done better or any plugin you find it worth to install.

First of all you need a Eclipse installation. I have chosen version 3.7.1 of the “Eclipse IDE for JavaScript Web Developers” (http://eclipse.org/downloads). The first plugin to install is yedit a YAML Editor plugin for Eclipse. There are others but I found this one the best of them.  To install yedit add the Update-Site (Help->Install new Software) in Eclipse. The URL of the Update-Site is http://dadacoalition.org/yedit.

PHP/Symfony

The next plugins to install are the PDT (PHP Development Tools) and the Symfony2 plugin. Now the bumpy road lies ahead of us. The Symfony2-Plugin is in beta state at the moment and needs a development-build of the PDT to work. So installation can produce “interessting” results in form of errors. For a detailed installation instruction consult the installation page of the project. Because of the dependencies and the development speed things will change frequently.
What will you get installing the plugin? Short answer: A bunch of great little helpers for editing Symfony2 Classes. Here is my favorite list:

  • Autocomplete of route-names in Twig-Templates
  • Code-Assist of Template-paths
  • Code-Assist of Container-Services
  • Annotation-Support
  • Code-Assist for translations

For a more complete list of features please consult the Projects homepage. Here some screenshots (taken from the projects homepage)

PHP Tool integration

Next step is to get a better PHP Tool integration. As I’m addicted to Tools such PHPUnit, CodeSniffer and others I love to have them integrated directly in the IDE. And thats a thing Eclipse is lacking so far. But as always rescue comes by installing a new plugin. In this case PTI(PHP Tool Integration, http://www.phpsrc.org). The Installation can be done via the Update-Site of the Plugin (http://www.phpsrc.org/eclipse/pti/). The current version brings support for PHPUnit, PHP_CodeSniffer, PHP Depends, PHP Copy/Paste Detector. The development speed slowed down the last months, so if you like the plugin just make sure you send you congratulations to Sven Kiera (Twitter)
After installing the plugin you will have to initially configure it in the preferences (there is a new category PHP Tools there)

After installing and congiguring you get new views for your IDE. In these you can start the tools and can work through the results of them.

WicketShell

Chances are good that you never heard anything about WicketShell, although it is a great plugin after all. WicketShell adds a Console Shell as an Eclipse view. This is pretty useful to execute Symfony-Commandline-Operations or doing other console stuff. This is even more useful if you are using Windows because of the lack of a good console. The development activity of the plugin is low but it is usefull nonetheless. The Update-Site for installation: http://www.wickedshell.net/updatesite

Code-Formatting

The default capabilities of Eclipse/PDT are two basic settings for the idention size and the Tab policy. Compared to the possibilities of Netbeans or PHPStorm this is a shame. Luckily there is a plugin for that :) PHP Code Formatter: http://de.sourceforge.jp/projects/pdt-tools/. There is no updatesite available at the time of writing this. So you will have to download the plugin file and install it as a file (archive) in the under Help->Install New software. After installing the plugin you can creating code formatting rules that fits your Coding Style (hopefully you have one). This is totaly handy for reformating your sources with the Ctrl+Shift+F Shortcut.

Version Control

Even for the support of a version control system you will have to install a plugin. Sometimes there are more than one for the same VCS (for SVN for example). As I’m working with GIT and Mercurial most of the time, I installed these two plugins:

Git: I use EGit, update-site here: http://download.eclipse.org/egit/updates
Mercurial: I use MercurialEclipse, update-site here: http://cbes.javaforge.com/update

Code Coloring

Maybe you are a fan of strong colors or love dark backgrounds in your Editor windows. If this is the case the Eclipse Color Theme plugin is definitly for you. After installing the plugin from its update-site (http://eclipse-color-theme.github.com/update) you can choose and install from a great set of different themes (http://www.eclipsecolorthemes.org/).

That’s it. That brings Eclipse on par with other IDEs. For some things (DI autocompletion, Annotation support) this installation will beat the others.

The installation still has the general problems of an Eclipse installation. The components should be touched / updated carefully. Better don’t touch then if everything is working. The Symfony2-Plugin is still beta and relies on a development build of the PDT, so any update here can break the IDE. But without this you will get a decent PHP/Symfony2 IDE and some features are really a joy to work with. Will I love it? Most probably not, but it is a good choice for all who doesn’t have the free choice or like Eclipse anyway.

23 responses to How to build a great Eclipse-Environment for Symfony2-Development

  1. Interesting article. Unfortunately I can’t find anything to download at the URL given for the PHP Code Formatter.

    JQ

  2. Cool!

  3. Nice collection! I think I will stay with vim and Textmate for now but maybe one day I’ll switch back to IDEs like Eclipse. :)

  4. another alternative to windows cli is cygwin + puttycyg

  5. Hey, creative thing you have posted here. Really helpful it is!

  6. I followed the instructions, however when I create a new Symfony project in Eclipse, I have a few hundred error in the vendor folder. Most of the errors have to do with missing implementation of some of the methods that the classes extend. e.g.:

    class OCI8Connection implements \Doctrine\DBAL\Driver\Connection

    gives the following errors:
    {code}
    Multiple annotations found at this line:
    - Missing method implementations: connect, getPortability, getFetchCase, executeQuery,
    - Missing method implementations: getParams, getDatabase, getHost, getPort, getUsername, getPassword, getDriver,
    getConfiguration, getEventManager, getDatabasePlatform, getExpressionBuilde
    {code}

    Any suggestions on what am I could be missing on my installation ?

    Thank you,

    –MD.

  7. @Marcio: The “Missing method implementations” warnings/errors will be solved in the next update of the symfony plugin. you can turn those validation errors of in the symfony preferences of your eclipse installation in the meantime.

  8. anyone got the formatter extension running? the japanese sourceforge site is somewhat confusing ;)

  9. To anyone who’s interested: I’ve contacted the author of the pretty cool formatter plugin, and he replied that he’s discontinued the development. So i integrated the (EPL licensed) code into my PDT Extensions plugin (https://github.com/pulse00/PDT-Extensions) which has a dedicated updatesite and some additional features like class + getter/setter generation etc. To sweeten the deal, i’ve packaged the YEdit Editor and the PDT Extension Feature into the Symfony plugin’s updatesite, so Symfony users will have one updatesite that covers a lot of symfony related goodies. Also, i’m in contact with the authors of WickedShell, and they said that they will create an extension point into their plugin to let other plugins provide codeassist. If that’s implemented, i can add content assist for symfony commands in wickedshell too.

  10. @pulse00 Wow that sounds cool. Keep up your efforts. Thumbs up :)

  11. Nice work Timo.
    Thumbs up pulse00, rock on!

  12. Simply doesn’t work.
    After creating new project:

    Description Resource Path Location Type
    cos-nonambig: WC[##other:"http://doctrine-project.org/schemas/orm/doctrine-mapping"] and WC[##other:"http://doctrine-project.org/schemas/orm/doctrine-mapping"] (or elements from their substitution group) violate “Unique Particle Attribution”. During validation against this schema, ambiguity would be created for those two particles. doctrine-mapping.xsd /testowy/vendor/doctrine line 113 XML Schema Problem
    cos-nonambig: WC[##other:"http://doctrine-project.org/schemas/orm/doctrine-mapping"] and WC[##other:"http://doctrine-project.org/schemas/orm/doctrine-mapping"] (or elements from their substitution group) violate “Unique Particle Attribution”. During validation against this schema, ambiguity would be created for those two particles. doctrine-mapping.xsd /testowy/vendor/doctrine line 371 XML Schema Problem
    cos-nonambig: WC[##other:"http://doctrine-project.org/schemas/orm/doctrine-mapping"] and WC[##other:"http://doctrine-project.org/schemas/orm/doctrine-mapping"] (or elements from their substitution group) violate “Unique Particle Attribution”. During validation against this schema, ambiguity would be created for those two particles. doctrine-mapping.xsd /testowy/vendor/doctrine line 389 XML Schema Problem
    cos-nonambig: WC[##other:"http://symfony.com/schema/dic/services"] and WC[##other:"http://symfony.com/schema/dic/services"] (or elements from their substitution group) violate “Unique Particle Attribution”. During validation against this schema, ambiguity would be created for those two particles. services-1.0.xsd /testowy/vendor/symfony/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services line 20 XML Schema Problem
    cvc-complex-type.2.3: Element ‘routes’ cannot have character [children], because the type’s content type is element-only. routing.xml /testowy/vendor/bundles/Sensio/Bundle/GeneratorBundle/Resources/skeleton/crud/config line 5 XML Problem
    cvc-complex-type.3.2.2: Attribute ‘default-locale’ is not allowed to appear in element ‘framework:session’. full.xml /testowy/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml line 15 XML Problem

    Regards

  13. pulse00, awesome. Keep your great project. It will be great if the repository offers a fail-safe-installation for sf users. Something like a eclipse indigo download + a version of all plugins that you’ve collected in a way that we can consider ‘stable’. I said that because sometimes we may try to update some of the plugins and get the IDE corrupted, so a plain new installation with everything working would be amazing.

  14. Hi all,

    I’ve got a problem to run the Symfony2 Plugin after a fresh install following the official tutorial. Eclipse (Indigo version) complains when building a new “Symfony Project” or adding “Symfony Nature” to an existing one. The error starts with something like:

    “Errors running builder ‘Script Builder’ on project ‘ProjectName’…”.

    Finally I’ve solved it, uninstalling the Symfony2 Plugin + PDT, and installing PHP Development Tools again through the Symfony2 Plugin Update Site (http://pulse00.github.com/Symfony-2-Eclipse-Plugin/). I hope it helps someone with the same error.

  15. having the same problems like pid with PDT from pulse00.

  16. @Gabriel, @daaawooo: The Symfony plugin has a new updatesite which simplified the installation: http://pulse00.github.com/p2/. Please see this blog post for details.

    @Gustavo: I was thinking about a All-In-One solution for Symfony users too. Basically something like the Zend-Studio for Symfony, but for free ;)

    Maybe i can create a build like that when i have more time.

  17. I was attempting to update Eclipse php helios (win32) with symfony2 plugin using http://pulse00.github.com/p2/ with install software from help in Eclipe and got this message…any ideas how to fix it?
    Cannot complete the install because one or more required items could not be found.
    Software being installed: Symfony Feature 1.0.61 (com.dubture.symfony.feature.feature.group 1.0.61)
    Missing requirement: Symfony Feature 1.0.61 (com.dubture.symfony.feature.feature.group 1.0.61) requires

  18. That’s a super-useful post, thanks Timo.

    By the way, @pgp: don’t use helios, use 3.7 (SR2) or higher. Juno works for me.

  19. @Pid and others:

    This is just the Eclipse XML Schema validators complaining so you just need to disable these.

    Open “Window > Preferences > XML > XML Files > Validation” and uncheck “Process XML inclusions” and “Honour all XML schema locations”.

    Then disable all validators: “Window > Preferences > Validation” and in the list, disable the following:

    XML Schema Validator
    XML Validator
    XSL Validator

    (or just check “Suspend all validators” to get it into a building state)

  20. Juno does not work for me…I cannot see the “New Symfony Project” wizard…

    using Juno and PDT 3.1.1

  21. I take back my previous comment…it’s working now…just had to reinstall everything from scratch…:-) Eclipse really likes to troll people with its bugginess..

  22. Nice articel, thanks ;).
    Symfony2 works great under eclipse JS. I love it!!!

Leave a reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>