A simple module enables composer autoloading for drupal modules.
This project can be checked out with composer.
{
"require": {
"janschumann/classloader_composer": "*"
}
}
Usually no configuration is necessary.
Only if you have changed the vendor-dir
configuration option in your composer.json
file, the absolute path to this directory has to be made available to drupal:
Via shell script:
$ drush vset composer_vendor_dir <path/to/vendor/dir>
Via php:
variable_set('composer_vendor_dir', '<path/to/vendor/dir>');
After this module is required in your project´s composer.json
file, composer will autoload all classes added to the composer.json
autoload section:
{
"autoload": {
"psr-0": {
"My\\Namespace\\": "src"
}
}
}