From e31a0f8296de39fa967f4e979e57b1836de086ff Mon Sep 17 00:00:00 2001 From: Sascha Egerer Date: Thu, 1 Aug 2013 08:44:07 +0200 Subject: [PATCH 1/2] Add pre-status-cmd and post-status-cmd hooks --- doc/articles/scripts.md | 2 ++ res/composer-schema.json | 8 ++++++++ src/Composer/Command/RunScriptCommand.php | 2 ++ src/Composer/Command/StatusCommand.php | 7 +++++++ src/Composer/Script/ScriptEvents.php | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+) 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..8f5ef7c58 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. * From c13327dd75467e9bb3822ddea9737a7aab73b051 Mon Sep 17 00:00:00 2001 From: Sascha Egerer Date: Thu, 1 Aug 2013 08:59:38 +0200 Subject: [PATCH 2/2] CGL fix --- src/Composer/Command/StatusCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index 8f5ef7c58..5151d734b 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -92,8 +92,8 @@ EOT $output->writeln('Use --verbose (-v) to see modified files'); } - // Dispatch post-status-command - $composer->getEventDispatcher()->dispatchCommandEvent(ScriptEvents::POST_STATUS_CMD, true); + // Dispatch post-status-command + $composer->getEventDispatcher()->dispatchCommandEvent(ScriptEvents::POST_STATUS_CMD, true); return $errors ? 1 : 0; }