diff --git a/doc/articles/scripts.md b/doc/articles/scripts.md index 7e6f9f41b..be777aa08 100644 --- a/doc/articles/scripts.md +++ b/doc/articles/scripts.md @@ -24,6 +24,8 @@ Composer fires the following named events during its execution process: - **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-status-cmd**: occurs before the `status` command is executed. +- **post-status-cmd**: occurs after the `status` 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. diff --git a/res/composer-schema.json b/res/composer-schema.json index 343b1bf9f..328794ef8 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -259,6 +259,14 @@ "type": ["array", "string"], "description": "Occurs after the update command is executed, contains one or more Class::method callables or shell commands." }, + "pre-status-cmd": { + "type": ["array", "string"], + "description": "Occurs before the status command is executed, contains one or more Class::method callables or shell commands." + }, + "post-status-cmd": { + "type": ["array", "string"], + "description": "Occurs after the status command is executed, contains one or more Class::method callables or shell commands." + }, "pre-package-install": { "type": ["array", "string"], "description": "Occurs before a package is installed, contains one or more Class::method callables or shell commands." diff --git a/src/Composer/Command/RunScriptCommand.php b/src/Composer/Command/RunScriptCommand.php index e504ce527..c4a3a3563 100644 --- a/src/Composer/Command/RunScriptCommand.php +++ b/src/Composer/Command/RunScriptCommand.php @@ -50,6 +50,8 @@ EOT ScriptEvents::POST_INSTALL_CMD, ScriptEvents::PRE_UPDATE_CMD, ScriptEvents::POST_UPDATE_CMD, + ScriptEvents::PRE_STATUS_CMD, + ScriptEvents::POST_STATUS_CMD, ))) { if (defined('Composer\Script\ScriptEvents::'.str_replace('-', '_', strtoupper($script)))) { throw new \InvalidArgumentException(sprintf('Script "%s" cannot be run with this command', $script)); diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index 4eaddda5c..5151d734b 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Composer\Downloader\ChangeReportInterface; use Composer\Downloader\VcsDownloader; +use Composer\Script\ScriptEvents; /** * @author Tiago Ribeiro @@ -50,6 +51,9 @@ EOT $dm = $composer->getDownloadManager(); $im = $composer->getInstallationManager(); + // Dispatch pre-status-command + $composer->getEventDispatcher()->dispatchCommandEvent(ScriptEvents::PRE_STATUS_CMD, true); + $errors = array(); // list packages @@ -88,6 +92,9 @@ EOT $output->writeln('Use --verbose (-v) to see modified files'); } + // Dispatch post-status-command + $composer->getEventDispatcher()->dispatchCommandEvent(ScriptEvents::POST_STATUS_CMD, true); + return $errors ? 1 : 0; } } diff --git a/src/Composer/Script/ScriptEvents.php b/src/Composer/Script/ScriptEvents.php index 0a608e301..5f3eaafd8 100644 --- a/src/Composer/Script/ScriptEvents.php +++ b/src/Composer/Script/ScriptEvents.php @@ -56,6 +56,24 @@ class ScriptEvents */ const POST_UPDATE_CMD = 'post-update-cmd'; + /** + * The PRE_STATUS_CMD event occurs before the status command is executed. + * + * The event listener method receives a Composer\Script\CommandEvent instance. + * + * @var string + */ + const PRE_STATUS_CMD = 'pre-status-cmd'; + + /** + * The POST_STATUS_CMD event occurs after the status command is executed. + * + * The event listener method receives a Composer\Script\CommandEvent instance. + * + * @var string + */ + const POST_STATUS_CMD = 'post-status-cmd'; + /** * The PRE_PACKAGE_INSTALL event occurs before a package is installed. *