Jens A. Koch

How to create a Composer Plugin…

Composer Plugins

Composer supports plugins. A plugins is directly activated, after it is downloaded.

You would simply need to add the plugin package to the require section of your composer.json.

When the plugin is instantiated the activate() method is called by Composer automatically.

You get access to the Composer instance and the IO.

You can now add your custom functionality: the new stuff your plugin does.

Referencing Composer/Plugin/PluginManager

Composer Plugin Events

A plugin can subscribe to Composer events.

When you want to extend the behavior of Composer itself, you might try combining the plugin with the event system.

Composer provides 4 main categories of events: Command, Installer, Package and Plugin events.
Just take a look at the full list of the event names.

To connect your plugin to the event system you will have to add a description table, explaining
which of your plugin methods should be called on a certain event.
This is done by declaring an array() in the static method getSubscribedEvents().

An array item looks like this:

This definition tells Composer, that the internal event PRE_PACKAGE_UPDATE should fire your onPrePackageUpdate() method.

The following example implementation of a Composer plugin contains several event bindings for demonstration purposes.
Each of the methods invoked by the event system will use the IO system to report when they are called.
This should give you an understanding of the order of events during an application run of Composer.


Comments Off on How to create a Composer Plugin…

Comments are closed.