You are here

abstract class SocialApiDataHandler in Social API 8.2

Same name and namespace in other branches
  1. 3.x 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
1 string reference to 'SocialApiDataHandler'
social_api.services.yml in ./social_api.services.yml
social_api.services.yml
1 service uses SocialApiDataHandler
social_api.data_handler in ./social_api.services.yml
Drupal\social_api\SocialApiDataHandler

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.