Changeset View
Changeset View
Standalone View
Standalone View
src/conduit/ArcanistConduitCallFuture.php
- This file was moved from src/conduit/ArcanistConduitCall.php.
| <?php | <?php | ||||
| final class ArcanistConduitCall | final class ArcanistConduitCallFuture | ||||
| extends Phobject { | extends FutureProxy { | ||||
| private $key; | |||||
| private $engine; | private $engine; | ||||
| private $method; | |||||
| private $parameters; | |||||
| private $future; | |||||
| public function setKey($key) { | |||||
| $this->key = $key; | |||||
| return $this; | |||||
| } | |||||
| public function getKey() { | |||||
| return $this->key; | |||||
| } | |||||
| public function setEngine(ArcanistConduitEngine $engine) { | public function setEngine(ArcanistConduitEngine $engine) { | ||||
| $this->engine = $engine; | $this->engine = $engine; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getEngine() { | public function getEngine() { | ||||
| return $this->engine; | return $this->engine; | ||||
| } | } | ||||
| public function setMethod($method) { | |||||
| $this->method = $method; | |||||
| return $this; | |||||
| } | |||||
| public function getMethod() { | |||||
| return $this->method; | |||||
| } | |||||
| public function setParameters(array $parameters) { | |||||
| $this->parameters = $parameters; | |||||
| return $this; | |||||
| } | |||||
| public function getParameters() { | |||||
| return $this->parameters; | |||||
| } | |||||
| private function newFuture() { | |||||
| if ($this->future) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Call has previously generated a future. Create a '. | |||||
| 'new call object for each API method invocation.')); | |||||
| } | |||||
| $method = $this->getMethod(); | |||||
| $parameters = $this->getParameters(); | |||||
| $future = $this->getEngine()->newFuture($this); | |||||
| $this->future = $future; | |||||
| return $this->future; | |||||
| } | |||||
| public function resolve() { | |||||
| if (!$this->future) { | |||||
| $this->newFuture(); | |||||
| } | |||||
| return $this->resolveFuture(); | |||||
| } | |||||
| private function resolveFuture() { | |||||
| $future = $this->future; | |||||
| try { | |||||
| $result = $future->resolve(); | |||||
| } catch (ConduitClientException $ex) { | |||||
| switch ($ex->getErrorCode()) { | |||||
| case 'ERR-INVALID-SESSION': | |||||
| if (!$this->getEngine()->getConduitToken()) { | |||||
| $this->raiseLoginRequired(); | |||||
| } | |||||
| break; | |||||
| case 'ERR-INVALID-AUTH': | |||||
| $this->raiseInvalidAuth(); | |||||
| break; | |||||
| } | |||||
| throw $ex; | |||||
| } | |||||
| return $result; | |||||
| } | |||||
| private function raiseLoginRequired() { | private function raiseLoginRequired() { | ||||
| $conduit_uri = $this->getEngine()->getConduitURI(); | $conduit_uri = $this->getEngine()->getConduitURI(); | ||||
| $conduit_uri = new PhutilURI($conduit_uri); | $conduit_uri = new PhutilURI($conduit_uri); | ||||
| $conduit_uri->setPath('/'); | $conduit_uri->setPath('/'); | ||||
| $conduit_domain = $conduit_uri->getDomain(); | $conduit_domain = $conduit_uri->getDomain(); | ||||
| $block = id(new PhutilConsoleBlock()) | $block = id(new PhutilConsoleBlock()) | ||||
| Show All 11 Lines | $block = id(new PhutilConsoleBlock()) | ||||
| pht( | pht( | ||||
| 'To login and save credentials for this server, run this '. | 'To login and save credentials for this server, run this '. | ||||
| 'command:')) | 'command:')) | ||||
| ->addParagraph( | ->addParagraph( | ||||
| tsprintf( | tsprintf( | ||||
| " $ arc install-certificate %s\n", | " $ arc install-certificate %s\n", | ||||
| $conduit_uri)); | $conduit_uri)); | ||||
| throw new ArcanistUsageException($block->drawConsoleString()); | throw new PhutilArgumentUsageException($block->drawConsoleString()); | ||||
| } | } | ||||
| private function raiseInvalidAuth() { | private function raiseInvalidAuth() { | ||||
| $conduit_uri = $this->getEngine()->getConduitURI(); | $conduit_uri = $this->getEngine()->getConduitURI(); | ||||
| $conduit_uri = new PhutilURI($conduit_uri); | $conduit_uri = new PhutilURI($conduit_uri); | ||||
| $conduit_uri->setPath('/'); | $conduit_uri->setPath('/'); | ||||
| $conduit_domain = $conduit_uri->getDomain(); | $conduit_domain = $conduit_uri->getDomain(); | ||||
| Show All 11 Lines | $block = id(new PhutilConsoleBlock()) | ||||
| pht( | pht( | ||||
| 'To login and save valid credentials for this server, run this '. | 'To login and save valid credentials for this server, run this '. | ||||
| 'command:')) | 'command:')) | ||||
| ->addParagraph( | ->addParagraph( | ||||
| tsprintf( | tsprintf( | ||||
| " $ arc install-certificate %s\n", | " $ arc install-certificate %s\n", | ||||
| $conduit_uri)); | $conduit_uri)); | ||||
| throw new ArcanistUsageException($block->drawConsoleString()); | throw new PhutilArgumentUsageException($block->drawConsoleString()); | ||||
| } | |||||
| protected function didReceiveResult($result) { | |||||
| return $result; | |||||
| } | |||||
| protected function didReceiveException($exception) { | |||||
| switch ($exception->getErrorCode()) { | |||||
| case 'ERR-INVALID-SESSION': | |||||
| if (!$this->getEngine()->getConduitToken()) { | |||||
| $this->raiseLoginRequired(); | |||||
| } | |||||
| break; | |||||
| case 'ERR-INVALID-AUTH': | |||||
| $this->raiseInvalidAuth(); | |||||
| break; | |||||
| } | |||||
| throw $exception; | |||||
| } | } | ||||
| } | } | ||||