Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add post-outdated-cmd and pre-outdated-cmd events #11818

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions res/composer-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,14 @@
"type": ["array", "string"],
"description": "Occurs after the update command is executed, contains one or more Class::method callables or shell commands."
},
"pre-outdated-cmd": {
"type": ["array", "string"],
"description": "Occurs before the outdated command is executed, contains one or more Class::method callables or shell commands."
},
"post-outdated-cmd": {
"type": ["array", "string"],
"description": "Occurs after the outdated 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."
Expand Down
20 changes: 19 additions & 1 deletion src/Composer/Command/OutdatedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace Composer\Command;

use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
use Composer\Script\ScriptEvents;
use Symfony\Component\Console\Input\InputInterface;
use Composer\Console\Input\InputArgument;
use Symfony\Component\Console\Input\ArrayInput;
Expand Down Expand Up @@ -110,7 +113,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$input = new ArrayInput($args);

return $this->getApplication()->run($input, $output);
$composer = $this->tryComposer();

if ($composer !== null) {
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'outdated', $input, $output);
$eventDispatcher = $composer->getEventDispatcher();
$eventDispatcher->dispatch($commandEvent->getName(), $commandEvent);
Comment on lines +119 to +121
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I orientated by the ArchiveCommand not sure if this additional dispatch is expected or the dispatchScript is enough to be added.

$eventDispatcher->dispatchScript(ScriptEvents::PRE_OUTDATED_CMD);
}

$returnCode = $this->getApplication()->run($input, $output);

if (0 === $returnCode && $composer !== null) {
$composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_OUTDATED_CMD);
}

return $returnCode;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Composer/Script/ScriptEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,22 @@ class ScriptEvents
* @var string
*/
public const POST_ARCHIVE_CMD = 'post-archive-cmd';

/**
* The PRE_OUTDATED_CMD event occurs before the outdated command is executed.
*
* The event listener method receives a Composer\Script\Event instance.
*
* @var string
*/
public const PRE_OUTDATED_CMD = 'pre-outdated-cmd';

/**
* The POST_OUTDATED_CMD event occurs after the outdated command is executed.
*
* The event listener method receives a Composer\Script\Event instance.
*
* @var string
*/
public const POST_OUTDATED_CMD = 'post-outdated-cmd';
}