Is there a way to make Composer run an installer plugin located in ./src/
?
The relevant docs are rather unclear as to how it should be done, assuming it's possible to begin with.
If not, the docs also seem to suggest that it's possible to install a plugin in COMPOSER_HOME, but say essentially nothing as to how this can be done — any pointers would be most welcome.
Just to clarify: the problem isn't about autoloading the class as much as it is making composer load the plugin when running composer install
or composer update
.
My project setup:
./app
…
./src
./src/Hello
./src/Hello/HelloPlugin.php
./vendor
…
The plugin file:
<?php # ./src/Hello/Hello.php
namespace Hello;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
class HelloPlugin implements PluginInterface
{
public function activate(Composer $composer, IOInterface $io);
{
echo "Hello World!".PHP_EOL;
}
} # END class
The relevant lines of the project's composer.json
file:
{
"name": "hello/world",
"type": "project",
"autoload": {
"psr-0": {
"Hello\\": "src/"
}
},
"require": {
"composer/installers": "~1.0",
"composer-plugin-api": "~1.0"
},
"extra": {
"class": ["Hello\\HelloPlugin"]
}
}
"autoload": {
"psr-0": {
"Hello\\": "src/"
}
}
The composer autoload
is used to load all the namespaces
of packages you require
in you project and it is not intended to load plugins during the composer install
or composer update
hook.
The only way to load your own plugin class, is to implement your own composer plugin, a normal package of type composer-plugin
, which will be used by composer to load your HelloPlugin
class. Otherwise, your plugin class will not be loaded during the composer install
hook.
I have built a composer-plugin
myself, here you can find it https://github.com/mnsami/composer-custom-directory-installer , for references.
And if you have more questions/or help, please don't hesitate to ask.