class WriteSafeSessionHandler in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php \Drupal\Core\Session\WriteSafeSessionHandler
Wraps another SessionHandlerInterface to prevent writes when not allowed.
Hierarchy
- class \Drupal\Core\Session\WriteSafeSessionHandler implements \Drupal\Core\Session\SessionHandlerInterface, WriteSafeSessionHandlerInterface
Expanded class hierarchy of WriteSafeSessionHandler
1 file declares its use of WriteSafeSessionHandler
- WriteSafeSessionHandlerTest.php in core/tests/ Drupal/ Tests/ Core/ Session/ WriteSafeSessionHandlerTest.php 
- Contains \Drupal\Tests\Core\Session\WriteSafeSessionHandlerTest.
1 string reference to 'WriteSafeSessionHandler'
- core.services.yml in core/core.services.yml 
- core/core.services.yml
1 service uses WriteSafeSessionHandler
File
- core/lib/ Drupal/ Core/ Session/ WriteSafeSessionHandler.php, line 13 
- Contains \Drupal\Core\Session\WriteSafeSessionHandler.
Namespace
Drupal\Core\SessionView source
class WriteSafeSessionHandler implements \SessionHandlerInterface, WriteSafeSessionHandlerInterface {
  /**
   * @var \SessionHandlerInterface
   */
  protected $wrappedSessionHandler;
  /**
   * Whether or not the session is enabled for writing.
   *
   * @var bool
   */
  protected $sessionWritable;
  /**
   * Constructs a new write safe session handler.
   *
   * @param \SessionHandlerInterface $wrapped_session_handler
   *   The underlying session handler.
   * @param bool $session_writable
   *   Whether or not the session should be initially writable.
   */
  public function __construct(\SessionHandlerInterface $wrapped_session_handler, $session_writable = TRUE) {
    $this->wrappedSessionHandler = $wrapped_session_handler;
    $this->sessionWritable = $session_writable;
  }
  /**
   * {@inheritdoc}
   */
  public function close() {
    return $this->wrappedSessionHandler
      ->close();
  }
  /**
   * {@inheritdoc}
   */
  public function destroy($session_id) {
    return $this->wrappedSessionHandler
      ->destroy($session_id);
  }
  /**
   * {@inheritdoc}
   */
  public function gc($max_lifetime) {
    return $this->wrappedSessionHandler
      ->gc($max_lifetime);
  }
  /**
   * {@inheritdoc}
   */
  public function open($save_path, $session_id) {
    return $this->wrappedSessionHandler
      ->open($save_path, $session_id);
  }
  /**
   * {@inheritdoc}
   */
  public function read($session_id) {
    return $this->wrappedSessionHandler
      ->read($session_id);
  }
  /**
   * {@inheritdoc}
   */
  public function write($session_id, $session_data) {
    if ($this
      ->isSessionWritable()) {
      return $this->wrappedSessionHandler
        ->write($session_id, $session_data);
    }
    else {
      return TRUE;
    }
  }
  /**
   * {@inheritdoc}
   */
  public function setSessionWritable($flag) {
    $this->sessionWritable = (bool) $flag;
  }
  /**
   * {@inheritdoc}
   */
  public function isSessionWritable() {
    return $this->sessionWritable;
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| WriteSafeSessionHandler:: | protected | property | Whether or not the session is enabled for writing. | |
| WriteSafeSessionHandler:: | protected | property | ||
| WriteSafeSessionHandler:: | public | function | ||
| WriteSafeSessionHandler:: | public | function | ||
| WriteSafeSessionHandler:: | public | function | ||
| WriteSafeSessionHandler:: | public | function | Returns whether or not a session may be written to storage. Overrides WriteSafeSessionHandlerInterface:: | |
| WriteSafeSessionHandler:: | public | function | ||
| WriteSafeSessionHandler:: | public | function | ||
| WriteSafeSessionHandler:: | public | function | Sets whether or not a session may be written to storage. Overrides WriteSafeSessionHandlerInterface:: | |
| WriteSafeSessionHandler:: | public | function | ||
| WriteSafeSessionHandler:: | public | function | Constructs a new write safe session handler. | 
