From 39ab5017aa7339f26d3a748adfb511a9aec6121a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 5 Feb 2012 16:27:55 +0100 Subject: [PATCH] Update scripts docs --- doc/faqs/scripts.md | 66 +++++++++++++++++++++++++++++++++++++++++ doc/faqs/triggers.md | 70 -------------------------------------------- 2 files changed, 66 insertions(+), 70 deletions(-) create mode 100644 doc/faqs/scripts.md delete mode 100644 doc/faqs/triggers.md diff --git a/doc/faqs/scripts.md b/doc/faqs/scripts.md new file mode 100644 index 000000000..7b50ae78c --- /dev/null +++ b/doc/faqs/scripts.md @@ -0,0 +1,66 @@ +# Scripts + +## What is a script? + +A script is a callback (defined as a static method) that will be called +when the event it listens on is triggered. + +**Scripts are only executed on the root package, not on the dependencies +that are installed.** + + +## Event types + +- **pre-install-cmd**: occurs before the install command is executed. +- **post-install-cmd**: occurs after the install command is executed. +- **pre-update-cmd**: occurs before the update command is executed. +- **post-update-cmd**: occurs after the update command is executed. +- **pre-package-install**: occurs before a package is installed. +- **post-package-install**: occurs after a package is installed. +- **pre-package-update**: occurs before a package is updated. +- **post-package-update**: occurs after a package is updated. +- **pre-package-uninstall**: occurs before a package has been uninstalled. +- **post-package-uninstall**: occurs after a package has been uninstalled. + + +## Defining scripts + +Scripts are defined by adding the `scripts` key to a project's `composer.json`. + +They are specified as an array of classes and static method names. + +The classes used as scripts must be autoloadable via Composer's autoload +functionality. + +Script definition example: + +```json +{ + "scripts": { + "post-update-cmd": "MyVendor\\MyClass::postUpdate", + "post-package-install": ["MyVendor\\MyClass::postPackageInstall"] + } +} +``` + +Script listener example: + +```php +getOperation()->getPackage(); + // do stuff + } +} +``` diff --git a/doc/faqs/triggers.md b/doc/faqs/triggers.md deleted file mode 100644 index 14bccbef5..000000000 --- a/doc/faqs/triggers.md +++ /dev/null @@ -1,70 +0,0 @@ -# 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: - -```json -{ - "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" - } - } -} -``` - -Trigger Example: - -```php -