1
0
Fork 0
composer/doc/faqs/triggers.md

69 lines
1.5 KiB
Markdown
Raw Normal View History

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
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?
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`.
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": {
"post_install": [
"MyVendor\\MyRootPackage\\MyClass::myStaticMethod"
],
"post_update": [
"MyVendor\\MyRootPackage\\MyClass::myStaticMethod2"
]
2012-01-24 17:08:41 +00:00
}
},
"autoload": {
"psr-0": {
"MyVendor\\MyRootPackage": "my/folder/path/that/contains/triggers/from/the/root/project"
2012-01-24 17:08:41 +00:00
}
}
}
```
2012-01-25 17:23:04 +00:00
Trigger Example:
```php
<?php
namespace MyVendor\MyRootPackage;
use Composer\Trigger\TriggerEvent;
class MyClass
{
public static function myStaticMethod(TriggerEvent $event)
{
// code...
}
public static function myStaticMethod2(TriggerEvent $event)
{
// code...
}
}
```
2012-01-24 17:08:41 +00:00
## Informations:
A declared trigger with non existent file will be ignored.