In 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:
│ ├── invoicepdf
│ └── vendormetadata.php
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 :]
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.
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.