Issue
I'm developing a Prestashop (PS) module but I want use composer to install some dependencies.
I found some problems to perform this task. First of all, how include autoload class inside vendor to use the package? and second how use it in my module?
Could you provide me an example?
Solution
Just include the autoload.php
file in you module file:
<?php
require_once('vendor/autoload.php');
class MyModule extends Module
{
...
}
Since your module file will (and should be) always be loaded first, this should be ok.
I believe there shouldn't be any conflicts between two such modules that use composer autoload, because the generated autoloaders have unique class names and the ComposerAutoload
class used during registering autoloader is somehow unregistered after the process.
The file structure:
/modules/mymodule/mymodule.php
/modules/mymodule/composer.json
/modules/mymodule/vendor/autoload.php
Edit:
If you're making a custom website (not just the module), I'd advise to use single composer root in root directory:
/composer.json
Then I'd add require ../vendor/autoload.php
in custom config file (check /config/config.inc.php
which custom config files are loaded)
Answered By - gskema
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.