How to chain loaders in Composer

Viewed 82

We have a workflow where we need to generate class proxies for generic autoloaded classes, so we'd like to tap into the Composer autoload process. What we would like to do is something like:

class ourAutoloader {
    function loadClass($class){
        $file=$this->composerAutoloader->findFile($class);
        $proxiedFile=$this->proxy($file);
        includeFile($proxiedFile);
    }
}

We found a way to do this by changing the bootstrap process:

    $composerAutoloader=require('vendor/autoload.php');
    $composerAutoloader->unregister();
    $ourAutoloader=new OurAutoloader($composerAutoloader);
    $ourAutoloader->register();

But we are looking for a way to activate this chaining mechanism from a package we are developing. That is, running composer require our/component should enable the loader proxying chain without the need to modify the main project bootstrap. So, is there any way to do something to this effect via composer.json or plugins?

0 Answers
Related