/** * @param UserEvent $event * @param \DCarbone\PHPConsulAPI\WriteOptions|null $writeOptions * @return array( * @type UserEvent|null user event that was fired or null on error * @type \DCarbone\PHPConsulAPI\WriteMeta write metadata * @type \DCarbone\PHPConsulAPI\Error error, if any * ) */ public function fire(UserEvent $event, WriteOptions $writeOptions = null) { $r = new Request('put', sprintf('v1/event/fire/%s', $event->Name), $this->c); $r->setWriteOptions($writeOptions); if ('' !== ($nf = $event->NodeFilter)) { $r->params->set('node', $nf); } if ('' !== ($sf = $event->ServiceFilter)) { $r->params->set('service', $sf); } if ('' !== ($tf = $event->TagFilter)) { $r->params->set('tag', $tf); } if ('' !== ($payload = $event->Payload)) { $r->body = $payload; } /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $wm = $this->buildWriteMeta($duration); if (null !== $err) { return [null, $wm, $err]; } list($data, $err) = $this->decodeBody($response->getBody()); if ($err !== null) { return [null, $wm, $err]; } return [new UserEvent($data), $wm, null]; }
/** * @param string $address * @param WriteOptions|null $writeOptions * @return \DCarbone\PHPConsulAPI\Error|null error, if any */ public function raftRemovePeerByAddress($address, WriteOptions $writeOptions = null) { $r = new Request('delete', 'v1/operator/raft/peer', $this->c); $r->setWriteOptions($writeOptions); $r->params->set('address', (string) $address); list($_, $_, $err) = $this->requireOK($this->doRequest($r)); return $err; }
/** * @param CatalogDeregistration $catalogDeregistration * @param \DCarbone\PHPConsulAPI\WriteOptions|null $writeOptions * @return array( * @type \DCarbone\PHPConsulAPI\WriteMeta write meta data * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function deregister(CatalogDeregistration $catalogDeregistration, WriteOptions $writeOptions = null) { $r = new Request('put', 'v1/catalog/deregister', $this->c, $catalogDeregistration); $r->setWriteOptions($writeOptions); list($duration, $_, $err) = $this->requireOK($this->doRequest($r)); $wm = $this->buildWriteMeta($duration); return [$wm, $err]; }
/** * @param PreparedQueryDefinition $query * @param WriteOptions|null $writeOptions * @return array( * @type \DCarbone\PHPConsulAPI\WriteMeta write metadata * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function update(PreparedQueryDefinition $query, WriteOptions $writeOptions = null) { $r = new Request('PUT', 'v1/query', $this->c, $query); $r->setWriteOptions($writeOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $_, $err) = $this->requireOK($this->doRequest($r)); $wm = $this->buildWriteMeta($duration); return [$wm, $err]; }
/** * @param string $id * @param \DCarbone\PHPConsulAPI\WriteOptions|null $writeOptions * @return array( * @type \DCarbone\PHPConsulAPI\Session\SessionEntry[]|null list of session entries or null on error * @type \DCarbone\PHPConsulAPI\WriteMeta|null write metadata or null on error * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function renew($id, WriteOptions $writeOptions = null) { if (!is_string($id)) { return [null, null, new Error(sprintf('%s::renew - "$id" must be string, %s seen.', get_class($this), gettype($id)))]; } $r = new Request('put', sprintf('v1/session/renew/%s', $id), $this->c); $r->setWriteOptions($writeOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->doRequest($r); $wm = $this->buildWriteMeta($duration); if (null !== $err) { return [null, $wm, $err]; } $code = $response->getStatusCode(); if (404 === $code) { return [null, $wm, null]; } if (200 !== $code) { return [null, $wm, new Error(sprintf('%s::renew - Unexpected response code %d. Reason: %s', get_class($this), $code, $response->getReasonPhrase()))]; } list($data, $err) = $this->decodeBody($response->getBody()); if (null !== $err) { return [null, $wm, $err]; } return [$this->_hydrateEntries($data), $wm, null]; }
/** * @param string $id * @param WriteOptions|null $writeOptions * @return array( * @type string cloned ACL id * @type \DCarbone\PHPConsulAPI\WriteMeta write meta data * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function cloneACL($id, WriteOptions $writeOptions = null) { $r = new Request('PUT', sprintf('v1/acl/clone/%s', $id), $this->c); $r->setWriteOptions($writeOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $wm = $this->buildWriteMeta($duration); if (null !== $err) { return [null, $wm, $err]; } list($data, $err) = $this->decodeBody($response->getBody()); return [$data, $wm, $err]; }
/** * @param KVPair $p * @param \DCarbone\PHPConsulAPI\WriteOptions $writeOptions * @return array( * @type \DCarbone\PHPConsulAPI\WriteMeta write metadata * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function release(KVPair $p, WriteOptions $writeOptions = null) { $r = new Request('put', sprintf('v1/kv/%s', $p->Key), $this->c); $r->setWriteOptions($writeOptions); $r->params->set('release', $p->Session); if (0 !== $p->Flags) { $r->params->set('flags', $p->Flags); } list($duration, $_, $err) = $this->requireOK($this->doRequest($r)); $wm = $this->buildWriteMeta($duration); return [$wm, $err]; }