You are here

public function NativeSessionStorage::setSaveHandler in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::setSaveHandler()

Registers session save handler as a PHP session handler.

To use internal PHP session save handlers, override this method using ini_set with session.save_handler and session.save_path e.g.

ini_set('session.save_handler', 'files'); ini_set('session.save_path', /tmp');

or pass in a NativeSessionHandler instance which configures session.save_handler in the constructor, for a template see NativeFileSessionHandler or use handlers in composer package drak/native-session

Parameters

AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $saveHandler:

Throws

\InvalidArgumentException

See also

http://php.net/session-set-save-handler

http://php.net/sessionhandlerinterface

http://php.net/sessionhandler

http://github.com/drak/NativeSession

2 calls to NativeSessionStorage::setSaveHandler()
NativeSessionStorage::__construct in vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php
Constructor.
PhpBridgeSessionStorage::__construct in vendor/symfony/http-foundation/Session/Storage/PhpBridgeSessionStorage.php
Constructor.

File

vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php, line 369

Class

NativeSessionStorage
This provides a base class for session attribute storage.

Namespace

Symfony\Component\HttpFoundation\Session\Storage

Code

public function setSaveHandler($saveHandler = null) {
  if (!$saveHandler instanceof AbstractProxy && !$saveHandler instanceof NativeSessionHandler && !$saveHandler instanceof \SessionHandlerInterface && null !== $saveHandler) {
    throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \\SessionHandlerInterface; or be null.');
  }

  // Wrap $saveHandler in proxy and prevent double wrapping of proxy
  if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
    $saveHandler = new SessionHandlerProxy($saveHandler);
  }
  elseif (!$saveHandler instanceof AbstractProxy) {
    $saveHandler = PHP_VERSION_ID >= 50400 ? new SessionHandlerProxy(new \SessionHandler()) : new NativeProxy();
  }
  $this->saveHandler = $saveHandler;
  if ($this->saveHandler instanceof \SessionHandlerInterface) {
    if (PHP_VERSION_ID >= 50400) {
      session_set_save_handler($this->saveHandler, false);
    }
    else {
      session_set_save_handler(array(
        $this->saveHandler,
        'open',
      ), array(
        $this->saveHandler,
        'close',
      ), array(
        $this->saveHandler,
        'read',
      ), array(
        $this->saveHandler,
        'write',
      ), array(
        $this->saveHandler,
        'destroy',
      ), array(
        $this->saveHandler,
        'gc',
      ));
    }
  }
}