1.2 KiB
1.2 KiB
Triggers
What is a trigger?
A trigger is an event that runs a script in a static method, defined by a project. This event is raised before and after each action (install, update).
Where are the event types defined?
It is in the constant property in Composer\\Trigger\\TriggerEvents
class.
How is it defined?
It is defined by adding the triggers
key in the extra
key to a project's
composer.json
or package's composer.json
.
It is specified as an array of classes with her static method, in associative array define the event's type.
The PSR-0 must be defined, otherwise the trigger will not be triggered.
For any given project:
{
"extra": {
"triggers": {
"post_install": [
"MyVendor\\MyRootPackage\\MyClass::myStaticMethod"
],
"post_update": [
"MyVendor\\MyRootPackage\\MyClass::myStaticMethod2"
]
}
},
"autoload": {
"psr-0": {
"MyVendor\\MyRootPackage": "my/folder/path/that/contains/triggers/from/the/root/project"
}
}
}
Informations:
A declared trigger with non existent file will be ignored.