Composer integration for projects from OXID eShop 4.9.6 on

ComposerIn the recent past, we’ve had requests for implementing composer in order to manage dependencies with 3rd party libraries for projects. That’s why we introduced an empty composer.json file in the modules/ directory so developers can use this superpower from now on: modules/composer.json.

By running composer install or composer update in the modules/ directory, composer installs all required components (mentioned in composer.json) to modules/vendor/ and creates a corresponding autoloader file. If this autoloader file will be found by your OXID eShop core, it will be automatically plugged in so developers can use their required libraries anywhere in their modules.

After running composer install, for example, your folder structure would look like this:

Implementation in OXID eShop

We introduced the registerComposerAutoLoad method in oxfuncitons to catch the mentioned composer autoloader. This way, it is possible to use your own composer file whenever you want, and to overwrite the registerComposerAutoLoad function in modules/functions.php for loading your autoloader. Be free to do it if you don’t want to use the pre-defined implementation :]

Composer usage

The basic usage of composer require and install are described in composer documentation. Please note that the autoloader is already included in OXID eShop as described earlier.

Why in the modules directory?

On the one hand, we want to separate project and OXID eShop composer configurations strictly to avoid possible file merging conflicts etc. on OXID eShop updates. Please note: OXID eShop itself doesn’t use any 3rd party components on the basis of composer yet. On the other hand, we didn’t want to mislead you guys about the current composer usage status: The request “Should we run composer install (update) for OXID eShop in order to get it work?” can clearly be answered negatively. The implementation you find here, is clearly tented to be used in your project only – for a start.

Safety indication

Currently, the module directory is publicly accessible. Please make sure to secure this directory with the correct access limitations via .htaccess (or similar) for denying direct vendor access if needed.

Have fun using this enhancement introduced with OXID eShop Commmunity and Professional Edition 4.9.6 and Enterprise Edition 5.2.6. Hope you like the implementation. If you have other proposals please let us know about it and leave your comment here.

 

 

 

0.00 avg. rating (0% score) - 0 votes
4 replies
  1. Joscha Krug says:

    Hi Anton,

    thank you for listening to the community and helping with composer. The way you implemented composer, is clearly the old default way from OXID, keeping all modules and related parts in the module directory. To be honest, i don’t think that’s the way that should be used.

    I would suggest a structure like this:
    – ROOT
    — vendor
    — SOME/LIB
    — web
    — OXID checked out here

    I know, that with that it would be not possible to have modules easyly copied anymore but that’s the same with your solution and we’re building a system for people using composer not for ftp-copying-people.

    Best regards,

    Joscha

    Reply
    • Anton Fedurtsya
      Anton Fedurtsya says:

      Thanks for your comment, Joscha. This integration is not yet intended to be used for setting up OXID with composer nor to automatically install modules or providing standardized modules – it is intended to be used in your personal projects in a first step. We are still working on a smooth and savvy composer integration for OXID runtime, and in this step want to move out the core from the document root, having in mind more than the composer integration ????

      Reply
      • Ivo says:

        When can we expect the mentioned composer integration for core?
        On github i cant see any moves into that direction and that makes me a bit nervous. ????

        Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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