@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 110 lines 2.8 kB view raw
1<?php 2 3/** 4 * @task docs Command Documentation 5 */ 6abstract class MetaMTAEmailTransactionCommand extends Phobject { 7 8 abstract public function getCommand(); 9 10 /** 11 * Return a brief human-readable description of the command effect. 12 * 13 * This should normally be one or two sentences briefly describing the 14 * command behavior. 15 * 16 * @return string Brief human-readable remarkup. 17 * @task docs 18 */ 19 abstract public function getCommandSummary(); 20 21 22 /** 23 * Return a one-line Remarkup description of command syntax for documentation. 24 * 25 * @return string Brief human-readable remarkup. 26 * @task docs 27 */ 28 public function getCommandSyntax() { 29 return '**!'.$this->getCommand().'**'; 30 } 31 32 /** 33 * Return a longer human-readable description of the command effect. 34 * 35 * This can be as long as necessary to explain the command. 36 * 37 * @return string|null Human-readable remarkup of whatever length is desired. 38 * @task docs 39 */ 40 public function getCommandDescription() { 41 return null; 42 } 43 44 abstract public function isCommandSupportedForObject( 45 PhabricatorApplicationTransactionInterface $object); 46 47 abstract public function buildTransactions( 48 PhabricatorUser $viewer, 49 PhabricatorApplicationTransactionInterface $object, 50 PhabricatorMetaMTAReceivedMail $mail, 51 $command, 52 array $argv); 53 54 public function getCommandAliases() { 55 return array(); 56 } 57 58 public function getCommandObjects() { 59 return array($this); 60 } 61 62 public static function getAllCommands() { 63 return id(new PhutilClassMapQuery()) 64 ->setAncestorClass(self::class) 65 ->setExpandMethod('getCommandObjects') 66 ->setUniqueMethod('getCommand') 67 ->execute(); 68 } 69 70 public static function getAllCommandsForObject( 71 PhabricatorApplicationTransactionInterface $object) { 72 73 $commands = self::getAllCommands(); 74 foreach ($commands as $key => $command) { 75 if (!$command->isCommandSupportedForObject($object)) { 76 unset($commands[$key]); 77 } 78 } 79 80 return $commands; 81 } 82 83 public static function getCommandMap(array $commands) { 84 assert_instances_of($commands, self::class); 85 86 $map = array(); 87 foreach ($commands as $command) { 88 $keywords = $command->getCommandAliases(); 89 $keywords[] = $command->getCommand(); 90 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)); 103 } 104 } 105 } 106 107 return $map; 108 } 109 110}