Changeset View
Changeset View
Standalone View
Standalone View
src/toolset/ArcanistWorkflow.php
<?php | <?php | ||||
abstract class ArcanistWorkflow extends Phobject { | abstract class ArcanistWorkflow extends Phobject { | ||||
private $runtime; | private $runtime; | ||||
private $toolset; | private $toolset; | ||||
private $arguments; | private $arguments; | ||||
private $configurationEngine; | private $configurationEngine; | ||||
private $configurationSourceList; | private $configurationSourceList; | ||||
private $conduitEngine; | private $conduitEngine; | ||||
private $promptMap; | |||||
/** | /** | ||||
* Return the command used to invoke this workflow from the command like, | * Return the command used to invoke this workflow from the command like, | ||||
* e.g. "help" for @{class:ArcanistHelpWorkflow}. | * e.g. "help" for @{class:ArcanistHelpWorkflow}. | ||||
* | * | ||||
* @return string The command a user types to invoke this workflow. | * @return string The command a user types to invoke this workflow. | ||||
*/ | */ | ||||
abstract public function getWorkflowName(); | abstract public function getWorkflowName(); | ||||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | abstract class ArcanistWorkflow extends Phobject { | ||||
public function canHandleSignal($signo) { | public function canHandleSignal($signo) { | ||||
return false; | return false; | ||||
} | } | ||||
public function handleSignal($signo) { | public function handleSignal($signo) { | ||||
throw new PhutilMethodNotImplementedException(); | throw new PhutilMethodNotImplementedException(); | ||||
} | } | ||||
protected function newPrompts() { | |||||
return array(); | |||||
} | |||||
protected function newPrompt($key) { | |||||
return id(new ArcanistPrompt()) | |||||
->setWorkflow($this) | |||||
->setKey($key); | |||||
} | |||||
public function hasPrompt($key) { | |||||
$map = $this->getPromptMap(); | |||||
return isset($map[$key]); | |||||
} | |||||
public function getPromptMap() { | |||||
if ($this->promptMap === null) { | |||||
$prompts = $this->newPrompts(); | |||||
assert_instances_of($prompts, 'ArcanistPrompt'); | |||||
$map = array(); | |||||
foreach ($prompts as $prompt) { | |||||
$key = $prompt->getKey(); | |||||
if (isset($map[$key])) { | |||||
throw new Exception( | |||||
pht( | |||||
'Workflow ("%s") generates two prompts with the same '. | |||||
'key ("%s"). Each prompt a workflow generates must have a '. | |||||
'unique key.', | |||||
get_class($this), | |||||
$key)); | |||||
} | |||||
$map[$key] = $prompt; | |||||
} | |||||
$this->promptMap = $map; | |||||
} | |||||
return $this->promptMap; | |||||
} | |||||
amckinley: Yes, exactly like this! | |||||
protected function getPrompt($key) { | |||||
$map = $this->getPromptMap(); | |||||
$prompt = idx($map, $key); | |||||
if (!$prompt) { | |||||
throw new Exception( | |||||
pht( | |||||
'Workflow ("%s") is requesting a prompt ("%s") but it did not '. | |||||
'generate any prompt with that name in "newPrompts()".', | |||||
get_class($this), | |||||
$key)); | |||||
} | |||||
return clone $prompt; | |||||
} | |||||
} | } |
Yes, exactly like this!