You are here

class InMemoryConfig in Rocket.Chat 8

Same name and namespace in other branches
  1. 8.2 modules/rocket_chat_api/src/RocketChat/InMemoryConfig.php \Drupal\rocket_chat_api\RocketChat\InMemoryConfig

Class InMemoryConfig keeps the config in memory.

@package RocketChat

Hierarchy

Expanded class hierarchy of InMemoryConfig

1 file declares its use of InMemoryConfig
RocketChatSettingsForm.php in src/Form/RocketChatSettingsForm.php
Contains \Drupal\rocket_chat\Form\RocketChatSettingsForm.

File

modules/rocket_chat_api/src/RocketChat/InMemoryConfig.php, line 17

Namespace

Drupal\rocket_chat_api\RocketChat
View source
class InMemoryConfig implements RocketChatConfigInterface {

  /**
   * Server URL.
   *
   * @var string
   *   Store's  the Server URL.
   */
  private $url;

  /**
   * User name.
   *
   * @var string
   *   Store's  the user name.
   */
  private $user;

  /**
   * User password.
   *
   * @var string
   *   Store's  the password.
   */
  private $password;

  /**
   * User ID.
   *
   * @var string
   *   Store's  the user ID.
   */
  private $uid;

  /**
   * User Access Token.
   *
   * @var string
   *   Store's the user token.
   */
  private $utk;

  /**
   * Debugging flag.
   *
   * @var bool
   *   Are we Debugging?
   */
  private $debug;

  /**
   * A Config type that holds stored values.
   *
   * @var RocketChatConfigInterface
   *   Hold a reference to a Interface that actually does store data.
   */
  private $superConfig;

  /**
   * InMemoryConfig constructor.
   *
   * @param \Drupal\rocket_chat_api\RocketChat\RocketChatConfigInterface $storedConfig
   *   Stored Config Object (READ ONLY).
   * @param string $user
   *   User name.
   * @param string $password
   *   User Password.
   */
  public function __construct(RocketChatConfigInterface &$storedConfig, &$user, &$password) {
    $this->superConfig = $storedConfig;
    $this->url = $storedConfig
      ->getElement('server', "http://localhost:3000");
    $this->user = $user;
    $this->password = $password;
    $this->uid = $storedConfig
      ->getElement('rocket_chat_uid');
    $this->utk = $storedConfig
      ->getElement('rocket_chat_uit');
  }

  /**
   * {@inheritdoc}
   */
  public function getElement($elementName, $default = NULL) {
    switch ($elementName) {
      case 'rocket_chat_url':
      case 'server':
        return $this->url;
      case 'rocket_chat_uid':
        return $this->uid;
      case 'rocket_chat_uit':
        return $this->utk;
      default:
        throw new \InvalidArgumentException("[{$elementName}] not found", 144);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setElement($elementName, $newValue) {
    switch ($elementName) {
      case 'rocket_chat_url':
      case 'server':
        return $this->url = $newValue;
      case 'rocket_chat_uid':
        return $this->uid = $newValue;
      case 'rocket_chat_uit':
        return $this->utk = $newValue;
      default:
        throw new \InvalidArgumentException("[{$elementName}] not found", 144);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function isDebug() {
    return $this->debug;
  }

  /**
   * {@inheritdoc}
   */
  public function getJsonDecoder() {
    return $this->superConfig
      ->getJsonDecoder();
  }

  /**
   * {@inheritdoc}
   */
  public function notify($message, $type) {
    return $this->superConfig
      ->notify($message, $type);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InMemoryConfig::$debug private property Debugging flag.
InMemoryConfig::$password private property User password.
InMemoryConfig::$superConfig private property A Config type that holds stored values.
InMemoryConfig::$uid private property User ID.
InMemoryConfig::$url private property Server URL.
InMemoryConfig::$user private property User name.
InMemoryConfig::$utk private property User Access Token.
InMemoryConfig::getElement public function Get a RocketChatConfigInterface Element. Overrides RocketChatConfigInterface::getElement
InMemoryConfig::getJsonDecoder public function Get a function pointer to the function to use for JsonDecodeing. Overrides RocketChatConfigInterface::getJsonDecoder
InMemoryConfig::isDebug public function Is this a Debug / verbose Run. Overrides RocketChatConfigInterface::isDebug
InMemoryConfig::notify public function Notify the backend. Overrides RocketChatConfigInterface::notify
InMemoryConfig::setElement public function Set an Element in the RocketChatConfigInterface. Overrides RocketChatConfigInterface::setElement
InMemoryConfig::__construct public function InMemoryConfig constructor.