2012-01-24 17:08:41 +00:00
|
|
|
# Triggers
|
|
|
|
|
|
|
|
## What is a trigger?
|
|
|
|
|
|
|
|
A trigger is an event that runs a script in a static method, defined by a
|
2012-01-24 23:22:12 +00:00
|
|
|
project. This event is raised before and after each action (install, update).
|
2012-01-24 17:08:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Where are the event types defined?
|
|
|
|
|
2012-01-24 23:22:12 +00:00
|
|
|
It is in the constant property in `Composer\\Trigger\\TriggerEvents` class.
|
2012-01-24 17:08:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
## 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`.
|
|
|
|
|
2012-01-24 23:22:12 +00:00
|
|
|
It is specified as an array of classes with her static method,
|
|
|
|
in associative array define the event's type.
|
2012-01-24 17:08:41 +00:00
|
|
|
|
|
|
|
The PSR-0 must be defined, otherwise the trigger will not be triggered.
|
|
|
|
|
|
|
|
For any given project:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"extra": {
|
|
|
|
"triggers": {
|
2012-01-24 23:22:12 +00:00
|
|
|
"post_install": [
|
|
|
|
"MyVendor\\MyRootPackage\\MyClass::myStaticMethod"
|
|
|
|
],
|
|
|
|
"post_update": [
|
|
|
|
"MyVendor\\MyRootPackage\\MyClass::myStaticMethod2"
|
|
|
|
]
|
2012-01-24 17:08:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"autoload": {
|
|
|
|
"psr-0": {
|
2012-01-24 23:22:12 +00:00
|
|
|
"MyVendor\\MyRootPackage": "my/folder/path/that/contains/triggers/from/the/root/project"
|
2012-01-24 17:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Informations:
|
|
|
|
|
|
|
|
A declared trigger with non existent file will be ignored.
|