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.
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:
{
"scripts": {
"post-update-cmd": "MyVendor\\MyClass::postUpdate",
"post-package-install": ["MyVendor\\MyClass::postPackageInstall"]
}
}
Script listener example:
<?php
namespace MyVendor;
class MyClass
{
public static function postUpdate($event)
{
// do stuff
}
public static function postPackageInstall($event)
{
$installedPackage = $event->getOperation()->getPackage();
// do stuff
}
}