API

Capabilities

Your plugin can be capable of providing a Resolver, a Downloader, and/or a Patcher.

Enabling a plugin capability

This functionality comes directly from Composer. In your plugin class, implement \Composer\Plugin\Capable. Your getCapabilities() method should return a list of capabilities that your plugin offers.

 1use Composer\Plugin\Capable;
 2use Composer\Plugin\PluginInterface;
 3use cweagans\Composer\Capability\Downloader\DownloaderProvider;
 4use cweagans\Composer\Capability\Patcher\PatcherProvider;
 5use cweagans\Composer\Capability\Resolver\ResolverProvider;
 6
 7class YourPlugin implements PluginInterface, Capable
 8{
 9    /**
10     * @inheritDoc
11     */
12    public function getCapabilities(): array
13    {
14        return [
15            ResolverProvider::class => YourResolverProvider::class,
16            DownloaderProvider::class => YourDownloaderProvider::class,
17            PatcherProvider::class => YourPatcherProvider::class,
18        ];
19    }
20    
21    [...]
22}

Providers

Next, you need to implement the provider for your capability. The provider is responsible for instantiating any capability classes that your plugin offers and returns a list of them. Rather than duplicating the code here, you should refer to \cweagans\Composer\Capability\Downloader\CoreDownloaderProvider, \cweagans\Composer\Capability\Patcher\CorePatcherProvider, and \cweagans\Composer\Capability\Resolver\CoreResolverProvider for examples of how to write these classes. Your provider should extend one of the base classes provided (\cweagans\Composer\Capability\Downloader\BaseDownloaderProvider, \cweagans\Composer\Capability\Patcher\BasePatcherProvider, or \cweagans\Composer\Capability\Resolver\BaseResolverProvider for a Downloader provider, a Patcher provider, or a Resolver provider respectively.

Capability classes

Finally, you should implement the actual capability classes that actually provide the functionality that you want to provide. There are base classes provided that you can extend to make this process easier - \cweagans\Composer\Downloader\DownloaderBase, \cweagans\Composer\Patcher\PatcherBase, and \cweagans\Composer\Resolver\ResolverBase for a Downloader, Patcher, or Resolver respectively. Otherwise, you will need to implement the appropriate interface (each of which lives in the same namespace as the corresponding base class).