1
0
Fork 0

Removed scripts documentation duplication, refactor to the dedicated article page

pull/502/head
Romain Neutron 2012-03-27 00:59:08 +02:00
parent 9f331a2192
commit 6844d7b572
2 changed files with 14 additions and 57 deletions

View File

@ -335,59 +335,7 @@ Example:
Composer allows you to hook into various parts of the installation process Composer allows you to hook into various parts of the installation process
through the use of scripts. through the use of scripts.
These events are supported: See [Scripts](articles/scripts.md) for events details and examples.
* **pre-install-cmd:** Occurs before the install command is executed, contains
one or more Class::method callables.
* **post-install-cmd:** Occurs after the install command is executed, contains
one or more Class::method callables.
* **pre-update-cmd:** Occurs before the update command is executed, contains
one or more Class::method callables.
* **post-update-cmd:** Occurs after the update command is executed, contains
one or more Class::method callables.
* **pre-package-install:** Occurs before a package is installed, contains one
or more Class::method callables.
* **post-package-install:** Occurs after a package is installed, contains one
or more Class::method callables.
* **pre-package-update:** Occurs before a package is updated, contains one or
more Class::method callables.
* **post-package-update:** Occurs after a package is updated, contains one or
more Class::method callables.
* **pre-package-uninstall:** Occurs before a package has been uninstalled,
contains one or more Class::method callables.
* **post-package-uninstall:** Occurs after a package has been uninstalled,
contains one or more Class::method callables.
For each of these events you can provide a static method on a class that will
handle it.
Example:
{
"scripts": {
"post-install-cmd": [
"Acme\\ScriptHandler::doSomething"
]
}
}
The event handler receives a `Composer\Script\Event` object as an argument,
which gives you access to the `Composer\Composer` instance through the
`getComposer` method.
namespace Acme;
use Composer\Script\Event;
class ScriptHandler
{
static public function doSomething(Event $event)
{
$composer = $event->getComposer();
// custom logic
}
}
### extra ### extra

View File

@ -40,24 +40,33 @@ Script definition example:
{ {
"scripts": { "scripts": {
"post-update-cmd": "MyVendor\\MyClass::postUpdate", "post-update-cmd": "MyVendor\\MyClass::postUpdate",
"post-package-install": ["MyVendor\\MyClass::postPackageInstall"] "post-package-install": [
"MyVendor\\MyClass::postPackageInstall"
]
} }
} }
Script listener example: The event handler receives a `Composer\Script\Event` object as an argument,
which gives you access to the `Composer\Composer` instance through the
`getComposer` method.
Using the previous example, here's an event listener example :
<?php <?php
namespace MyVendor; namespace MyVendor;
use Composer\Script\Event;
class MyClass class MyClass
{ {
public static function postUpdate($event) public static function postUpdate(Event $event)
{ {
$composer = $event->getComposer();
// do stuff // do stuff
} }
public static function postPackageInstall($event) public static function postPackageInstall(Event $event)
{ {
$installedPackage = $event->getOperation()->getPackage(); $installedPackage = $event->getOperation()->getPackage();
// do stuff // do stuff