You are here

public function KeyClient::set in Lockr 7

Same name and namespace in other branches
  1. 7.2 vendor/lockr/lockr-client/src/KeyClient.php \Lockr\KeyClient::set()

Sets a key in Lockr.

Parameters

string $name The key name.:

string $value The key value.:

string $label The key label.:

Return value

string Returns the decrypt data or true.

File

src/Lockr/KeyClient.php, line 79

Class

KeyClient

Namespace

Lockr

Code

public function set($name, $value, $label, $encoded = null) {
  if ($this->encoded) {
    if ($encoded === NULL) {
      list($value, $encoded) = $this
        ->encrypt($value);
    }
    else {
      list($value, $encoded) = $this
        ->reencrypt($value, $encoded);
    }
  }
  $data = array(
    'key_value' => $value,
    'key_label' => $label,
  );
  list($status, $body) = $this->client
    ->patch($this
    ->uri($name), $data);
  if ($status >= 500) {
    throw new ServerException($body);
  }
  if ($status >= 400) {
    throw new ClientException($body);
  }
  if ($this->encoded) {
    return $encoded;
  }
  return true;
}