Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / metamta / command / MetaMTAEmailTransactionCommand.php
blob4a7102595f4c5c22fa53dbf289c97785b0592b1b
1 <?php
3 /**
4 * @task docs Command Documentation
5 */
6 abstract class MetaMTAEmailTransactionCommand extends Phobject {
8 abstract public function getCommand();
10 /**
11 * Return a brief human-readable description of the command effect.
13 * This should normally be one or two sentences briefly describing the
14 * command behavior.
16 * @return string Brief human-readable remarkup.
17 * @task docs
19 abstract public function getCommandSummary();
22 /**
23 * Return a one-line Remarkup description of command syntax for documentation.
25 * @return string Brief human-readable remarkup.
26 * @task docs
28 public function getCommandSyntax() {
29 return '**!'.$this->getCommand().'**';
32 /**
33 * Return a longer human-readable description of the command effect.
35 * This can be as long as necessary to explain the command.
37 * @return string Human-readable remarkup of whatever length is desired.
38 * @task docs
40 public function getCommandDescription() {
41 return null;
44 abstract public function isCommandSupportedForObject(
45 PhabricatorApplicationTransactionInterface $object);
47 abstract public function buildTransactions(
48 PhabricatorUser $viewer,
49 PhabricatorApplicationTransactionInterface $object,
50 PhabricatorMetaMTAReceivedMail $mail,
51 $command,
52 array $argv);
54 public function getCommandAliases() {
55 return array();
58 public function getCommandObjects() {
59 return array($this);
62 public static function getAllCommands() {
63 return id(new PhutilClassMapQuery())
64 ->setAncestorClass(__CLASS__)
65 ->setExpandMethod('getCommandObjects')
66 ->setUniqueMethod('getCommand')
67 ->execute();
70 public static function getAllCommandsForObject(
71 PhabricatorApplicationTransactionInterface $object) {
73 $commands = self::getAllCommands();
74 foreach ($commands as $key => $command) {
75 if (!$command->isCommandSupportedForObject($object)) {
76 unset($commands[$key]);
80 return $commands;
83 public static function getCommandMap(array $commands) {
84 assert_instances_of($commands, __CLASS__);
86 $map = array();
87 foreach ($commands as $command) {
88 $keywords = $command->getCommandAliases();
89 $keywords[] = $command->getCommand();
91 foreach ($keywords as $keyword) {
92 $keyword = phutil_utf8_strtolower($keyword);
93 if (empty($map[$keyword])) {
94 $map[$keyword] = $command;
95 } else {
96 throw new Exception(
97 pht(
98 'Mail commands "%s" and "%s" both respond to keyword "%s". '.
99 'Keywords must be uniquely associated with commands.',
100 get_class($command),
101 get_class($map[$keyword]),
102 $keyword));
107 return $map;