diff --git a/src/conduit/ArcanistConduitCall.php b/src/conduit/ArcanistConduitCall.php index 29e67762..bd25ff19 100644 --- a/src/conduit/ArcanistConduitCall.php +++ b/src/conduit/ArcanistConduitCall.php @@ -1,155 +1,153 @@ key = $key; return $this; } public function getKey() { return $this->key; } public function setEngine(ArcanistConduitEngine $engine) { $this->engine = $engine; return $this; } public function getEngine() { 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(); } - $this->getEngine()->resolveFuture($this->getKey()); - 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() { $conduit_uri = $this->getEngine()->getConduitURI(); $conduit_uri = new PhutilURI($conduit_uri); $conduit_uri->setPath('/'); $conduit_domain = $conduit_uri->getDomain(); $block = id(new PhutilConsoleBlock()) ->addParagraph( tsprintf( '** %s **', pht('LOGIN REQUIRED'))) ->addParagraph( pht( 'You are trying to connect to a server ("%s") that you do not '. 'have any stored credentials for, but the command you are '. 'running requires authentication.', $conduit_domain)) ->addParagraph( pht( 'To login and save credentials for this server, run this '. 'command:')) ->addParagraph( tsprintf( " $ arc install-certificate %s\n", $conduit_uri)); throw new ArcanistUsageException($block->drawConsoleString()); } private function raiseInvalidAuth() { $conduit_uri = $this->getEngine()->getConduitURI(); $conduit_uri = new PhutilURI($conduit_uri); $conduit_uri->setPath('/'); $conduit_domain = $conduit_uri->getDomain(); $block = id(new PhutilConsoleBlock()) ->addParagraph( tsprintf( '** %s **', pht('INVALID CREDENTIALS'))) ->addParagraph( pht( 'Your stored credentials for this server ("%s") are not valid.', $conduit_domain)) ->addParagraph( pht( 'To login and save valid credentials for this server, run this '. 'command:')) ->addParagraph( tsprintf( " $ arc install-certificate %s\n", $conduit_uri)); throw new ArcanistUsageException($block->drawConsoleString()); } } diff --git a/src/conduit/ArcanistConduitEngine.php b/src/conduit/ArcanistConduitEngine.php index 7533d463..7817f52c 100644 --- a/src/conduit/ArcanistConduitEngine.php +++ b/src/conduit/ArcanistConduitEngine.php @@ -1,140 +1,108 @@ conduitURI !== null); } public function setConduitURI($conduit_uri) { $this->conduitURI = $conduit_uri; return $this; } public function getConduitURI() { return $this->conduitURI; } public function setConduitToken($conduit_token) { $this->conduitToken = $conduit_token; return $this; } public function getConduitToken() { return $this->conduitToken; } public function setConduitTimeout($conduit_timeout) { $this->conduitTimeout = $conduit_timeout; return $this; } public function getConduitTimeout() { return $this->conduitTimeout; } public function newCall($method, array $parameters) { if ($this->conduitURI == null) { $this->raiseURIException(); } - $next_key = ++$this->callKey; - return id(new ArcanistConduitCall()) - ->setKey($next_key) ->setEngine($this) ->setMethod($method) ->setParameters($parameters); } public function resolveCall($method, array $parameters) { return $this->newCall($method, $parameters)->resolve(); } public function newFuture(ArcanistConduitCall $call) { $method = $call->getMethod(); $parameters = $call->getParameters(); $future = $this->getClient()->callMethod($method, $parameters); - $this->activeFutures[$call->getKey()] = $future; + return $future; } private function getClient() { if (!$this->client) { $conduit_uri = $this->getConduitURI(); $client = new ConduitClient($conduit_uri); $timeout = $this->getConduitTimeout(); if ($timeout) { $client->setTimeout($timeout); } $token = $this->getConduitToken(); if ($token) { $client->setConduitToken($this->getConduitToken()); } } return $client; } - public function resolveFuture($key) { - if (isset($this->resolvedFutures[$key])) { - return; - } - - if (!isset($this->activeFutures[$key])) { - throw new Exception( - pht( - 'No future with key "%s" is present in pool.', - $key)); - } - - $iterator = new FutureIterator($this->activeFutures); - foreach ($iterator as $future_key => $future) { - $this->resolvedFutures[$future_key] = $future; - unset($this->activeFutures[$future_key]); - if ($future_key == $key) { - break; - } - } - - return; - } - private function raiseURIException() { $list = id(new PhutilConsoleList()) ->addItem( pht( 'Run in a working copy with "phabricator.uri" set in ".arcconfig".')) ->addItem( pht( 'Set a default URI with `arc set-config phabricator.uri `.')) ->addItem( pht( 'Specify a URI explicitly with `--config phabricator.uri=`.')); $block = id(new PhutilConsoleBlock()) ->addParagraph( pht( 'This command needs to communicate with Phabricator, but no '. 'Phabricator URI is configured.')) ->addList($list); throw new ArcanistUsageException($block->drawConsoleString()); } }