You are here

abstract class SocialApiDataHandler in Social API 3.x

Same name and namespace in other branches
  1. 8.2 src/SocialApiDataHandler.php \Drupal\social_api\SocialApiDataHandler

Variables are written to and read from session via this class.

Hierarchy

Expanded class hierarchy of SocialApiDataHandler

1 file declares its use of SocialApiDataHandler
UserAuthenticator.php in src/User/UserAuthenticator.php

File

src/SocialApiDataHandler.php, line 10

Namespace

Drupal\social_api
View source
abstract class SocialApiDataHandler {

  /**
   * The session service.
   *
   * @var \Symfony\Component\HttpFoundation\Session\SessionInterface
   */
  protected $session;

  /**
   * The prefix each session variable will have.
   *
   * @var string
   */
  protected $sessionPrefix;

  /**
   * Constructor.
   *
   * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
   *   Used for reading data from and writing data to session.
   */
  public function __construct(SessionInterface $session) {
    $this->session = $session;
  }

  /**
   * Gets a session variable by key.
   *
   * @param string $key
   *   The session variable key.
   *
   * @return mixed
   *   The session variable value.
   */
  public function get($key) {
    return $this->session
      ->get($this
      ->getSessionPrefix() . $key);
  }

  /**
   * Sets a new session variable.
   *
   * @param string $key
   *   The session variable key.
   * @param mixed $value
   *   The session variable value.
   */
  public function set($key, $value) {
    $this->session
      ->set($this
      ->getSessionPrefix() . $key, $value);
  }

  /**
   * Gets the session prefix for the data handler.
   *
   * @return string
   *   The session prefix.
   */
  public function getSessionPrefix() {
    return $this->sessionPrefix;
  }

  /**
   * Sets the session prefix for the data handler.
   *
   * @param string $prefix
   *   The session prefix.
   */
  public function setSessionPrefix($prefix) {
    $this->sessionPrefix = $prefix . '_';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SocialApiDataHandler::$session protected property The session service.
SocialApiDataHandler::$sessionPrefix protected property The prefix each session variable will have.
SocialApiDataHandler::get public function Gets a session variable by key.
SocialApiDataHandler::getSessionPrefix public function Gets the session prefix for the data handler.
SocialApiDataHandler::set public function Sets a new session variable.
SocialApiDataHandler::setSessionPrefix public function Sets the session prefix for the data handler.
SocialApiDataHandler::__construct public function Constructor.