You are here

class LockrApiException in Lockr 7.3

Hierarchy

Expanded class hierarchy of LockrApiException

4 files declare their use of LockrApiException
lockr.admin.inc in ./lockr.admin.inc
Form callbacks for Lockr register form.
lockr.inc in plugins/key_provider/lockr.inc
Key provider plugin for lockr.
lockr.module in ./lockr.module
Hook implementations and callbacks for lockr.
LockrClient.php in vendor/lockr/lockr/src/LockrClient.php

File

vendor/lockr/lockr/src/Exception/LockrApiException.php, line 6

Namespace

Lockr\Exception
View source
class LockrApiException extends Exception {

  /** @var array $errors */
  private $errors;
  public function __construct(array $errors = []) {
    $this->errors = $errors;
    $msg = $this
      ->buildMessage();
    $code = $this
      ->divineCode();
    parent::__construct($msg, $code);
  }

  /**
   * @return array
   */
  public function getErrors() {
    return $this->errors;
  }
  public function buildMessage() {
    if (!$this->errors) {
      return '';
    }
    $err = $this->errors[0];
    $msg = $err['message'];
    if (count($this->errors) > 1) {
      $extra = count($this->errors) - 1;
      $msg .= " (and {$extra} more)";
    }
    return $msg;
  }
  public function divineCode() {
    foreach ($this->errors as $err) {
      if (!empty($err['extensions']['status_code'])) {
        return (int) $err['extensions']['status_code'];
      }
    }
    return 0;
  }

}

Members