Optimize Eclipse and Zend studio refresh in Magento projects with the resources filters

If you’re using Zend Studio or eclipse and have kept the native structure of a Magento project (in its first version), refreshing a project could sometime be a long task.

This is partly due to the number of files that change and need to be refreshed: Magento needs to take their new content into account.

To avoid refreshing every file changing frequently, you can exclude them: they won’t appear in the project folder, and so, won’t be

Continue reading “Optimize Eclipse and Zend studio refresh in Magento projects with the resources filters”

Have Zend Studio and Eclipse PDT faster with Magento projects: the build path configuration

Eclipse PDT editors like Zend Studio analyse the PHP source code to enable autocompletion: they analyze source files and index content found in

Magento embeds more than 10000 files (7000 php files) in Magento Do we need to index all content? no

To ensure that eclipse and Zend studio will offer you all the expected functionalities, you can make it faster, by removing all the non required editor files from editing build path.

What is Zend studio and Eclipse PDT build path?

Build path defines classpath for your project: folders that will be analyzed by editors to index content and where look for methods.

All build path sources defined within will be made available for Content Assist options, including source code completion

Basic configuration of the build path directive in Magento projects

Folders that we can remove from build path could be the following ones:

  • var: contains variables Magento data. Too much volatil, there is no real reason to include it in build path
  • media: all media elements used on your website. It should contain all picture files from your website and so there is no reason to analyse binary sources
  • skin: even if skin folder can contain js files, we can remove it
  • app/locale: for the time being, there is no link between magento translations calls and translations files. so we can also remove it
  • app/etc: like translations files, we can remove it
  • If you do not enable javascript support on your magento project, you can also remove the js folder

    How to configure build path with Zend Studio and eclipse PDT?

    On your Magento project, click right on the project and edit the build path configuration menu through the menu configure build path

    You’ll have a new window which look like this one:

    And then edit the excluded folders in list. When finished, eclipse will rebuild the build path with your new configuration

    By updating the build path, you can reduce by 30 percent number of files analyzed by eclipse. Even if you use some ssd disks, your eclipse should be faster. so if you use some slower disks or use shared networks folders, you should not forget to use this configuration value

    A Magento plugin for Eclipse and Zend Studio

    Magento has now its own dedicated eclipse / Zend studio plugin!

    This plugin

    • enable auto-completion without require to add the /* @var */ tag.
    • Provide a module creator

    It require for now

    • Eclipse 3.6 or higher with PDT 2.2.0 or higher
    • Zend Studio 7 or higher

    For now, it’s a 1.0.2 version

    Eclipse Magento plugin installation

    Just add the repository location (for now http://magento-plugin.googlecode.com/svn/update_site) to yours software update sites in the help > install new software menu and then install plugin

    When your plugin has been installed, just activate the Magento support to your module by a rick click on your project > Magento plugin > Add Magento nature

    Firsts usage feedbacks

    I like the module creator. it generate only the required elements to have a required module. The classic coding conventions are used. Yes for now it’s minimalist, but this first release is promising

    Autocomplete in Magento projects with Zend Studio or Eclipse PDT

    Source code autocomplete is not very easy in Magento projects. But there is a way that allows to fully have these features.

    Why is source code autocomplete so complicated to have in Magento projects?

    As I mentionned before, there is multiples ways to overload native Magento API. The active overloading mechanism allows you to overload a class with another different class simply by setting up a configuration value. But usage of these overloading mechanims make difficult to provide a PHPDoc which allows autocomplete:

    • which tag @return do I need to used?
    • Which object is returned by the call of Mage::getModel(‘catalog/product’) instruction?

    Very difficult for Varien to provide an answer: it depends on your configuration, and so, autocomplete is often very difficult to have.

    However, there is a way to have it with Zend Studio or PDT: no more loosing time to search a function signature or a block content, you can have with Zend Studio or PDT the fully autocomplete of your code

    All will be done with the @var tag

    The @var tag for code source autocomplete

    Is the @var tag a PHPDoc tag?

    No: This tag is not a PHPDoc compliant tag, but an extension available to complete PHPDoc

    Syntax of @var tag

    This tag is defined as followed:

    /* @var $variable Class_Type */

    Be sure to provide a simple * instead of the two required in PHPDoc

    Where to put the @var tag?

    This tag must be placed after variable definition, on the same line or on the following ones: the editor will be able to match variables with related classes only after it has found this instruction.

    So there is no difficulty to do that, just take time to well comment your source code

    Usage example of @var tag in Magento source code

    Template usage of the @var tag

    Without any @var tag in our template, we can’t have any code autocomplete:

    If we have the @var tag in top part of the template, now we are able to see all availables methods:

    getModel and getSingleton instruction

    Loading classes and collection is often boring without autocomplete

    $collection = Mage::getModel('catalog/product')->getCollection();

    using the @var tag will offer you all availables methods. try this code in a Magento project:

    $collection = Mage::getModel('catalog/product')->getCollection();
    /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */

    Conclusion on @var tag

    This tag allows you only with CTRL+Space shortcut to have every availables methods on objects referenced. I’m sure that you’ll find that this way will allow you to earn time in your projects