You are here

class ConnectorException in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 src/ConnectorException.php \Drupal\acquia_connector\ConnectorException
  2. 3.x src/ConnectorException.php \Drupal\acquia_connector\ConnectorException

Produce an exception for certain cases in the connector.

@package Drupal\acquia_connector

Hierarchy

  • class \Drupal\acquia_connector\ConnectorException extends \Drupal\acquia_connector\Exception

Expanded class hierarchy of ConnectorException

3 files declare their use of ConnectorException
CredentialForm.php in src/Form/CredentialForm.php
SettingsForm.php in src/Form/SettingsForm.php
SetupForm.php in src/Form/SetupForm.php

File

src/ConnectorException.php, line 10

Namespace

Drupal\acquia_connector
View source
class ConnectorException extends \Exception {

  /**
   * Custom exception messages.
   *
   * @var string[]
   *   Exception messages as key => value.
   */
  private $custom = [];

  /**
   * ConnectorException constructor.
   *
   * @param string $message
   *   Exception message.
   * @param int $code
   *   Exception code.
   * @param array $custom
   *   Exception messages as key => value.
   * @param \Exception|null $previous
   *   The previous exception used for the exception chaining. Since 5.3.0.
   */
  public function __construct($message, $code = 0, array $custom = [], \Exception $previous = NULL) {
    parent::__construct($message, $code, $previous);
    $this->custom = $custom;
  }

  /**
   * Check is customized.
   *
   * @return bool
   *   TRUE if not custom message is not empty, FALSE otherwise.
   */
  public function isCustomized() {
    return !empty($this->custom);
  }

  /**
   * Set custom message.
   *
   * @param mixed $value
   *   Custom message value.
   * @param string $key
   *   Custom message key.
   */
  public function setCustomMessage($value, $key = 'message') {
    $this->custom[$key] = $value;
  }

  /**
   * Get custom message.
   *
   * @param string $key
   *   Custom message key.
   * @param bool $fallback
   *   Default is TRUE. Return standard code or message.
   *
   * @return mixed
   *   Custom message of FALSE.
   */
  public function getCustomMessage($key = 'message', $fallback = TRUE) {
    if (isset($this->custom[$key])) {
      return $this->custom[$key];
    }
    if (!$fallback) {
      return FALSE;
    }
    switch ($key) {
      case 'code':
        return $this
          ->getCode();
      case 'message':
        return $this
          ->getMessage();
    }
    return FALSE;
  }

  /**
   * Get all custom messages.
   *
   * @return array
   *   Array of custom messages.
   */
  public function getAllCustomMessages() {
    return $this->custom;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConnectorException::$custom private property Custom exception messages.
ConnectorException::getAllCustomMessages public function Get all custom messages.
ConnectorException::getCustomMessage public function Get custom message.
ConnectorException::isCustomized public function Check is customized.
ConnectorException::setCustomMessage public function Set custom message.
ConnectorException::__construct public function ConnectorException constructor.