MigratingSessionHandler

class MigratingSessionHandler implements SessionHandlerInterface, SessionUpdateTimestampHandlerInterface

Migrating session handler for migrating from one handler to another. It reads from the current handler and writes both the current and new ones.

It ignores errors from the new handler.

Methods

public __construct(SessionHandlerInterface $currentHandler, SessionHandlerInterface $writeOnlyHandler) No description
public close() {@inheritdoc}
public destroy($sessionId) {@inheritdoc}
public gc($maxlifetime) {@inheritdoc}
public open($savePath, $sessionName) {@inheritdoc}
public read($sessionId) {@inheritdoc}
public write($sessionId, $sessionData) {@inheritdoc}
public validateId($sessionId) {@inheritdoc}
public updateTimestamp($sessionId, $sessionData) {@inheritdoc}

Details

at line 28

__construct()

public __construct(SessionHandlerInterface $currentHandler, SessionHandlerInterface $writeOnlyHandler)

Parameters

SessionHandlerInterface $currentHandler
SessionHandlerInterface $writeOnlyHandler
at line 44

close()

public close()

{@inheritdoc}

at line 55

destroy()

public destroy($sessionId)

{@inheritdoc}

Parameters

$sessionId
at line 66

gc()

public gc($maxlifetime)

{@inheritdoc}

Parameters

$maxlifetime
at line 77

open()

public open($savePath, $sessionName)

{@inheritdoc}

Parameters

$savePath
$sessionName
at line 88

read()

public read($sessionId)

{@inheritdoc}

Parameters

$sessionId
at line 97

write()

public write($sessionId, $sessionData)

{@inheritdoc}

Parameters

$sessionId
$sessionData
at line 108

validateId()

public validateId($sessionId)

{@inheritdoc}

Parameters

$sessionId
at line 117

updateTimestamp()

public updateTimestamp($sessionId, $sessionData)

{@inheritdoc}

Parameters

$sessionId
$sessionData

Source code

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;

/**
 * Migrating session handler for migrating from one handler to another. It reads
 * from the current handler and writes both the current and new ones.
 *
 * It ignores errors from the new handler.
 *
 * @author Ross Motley <ross.motley@amara.com>
 * @author Oliver Radwell <oliver.radwell@amara.com>
 */
class MigratingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
{
    private $currentHandler;
    private $writeOnlyHandler;

    public function __construct(\SessionHandlerInterface $currentHandler, \SessionHandlerInterface $writeOnlyHandler)
    {
        if (!$currentHandler instanceof \SessionUpdateTimestampHandlerInterface) {
            $currentHandler = new StrictSessionHandler($currentHandler);
        }
        if (!$writeOnlyHandler instanceof \SessionUpdateTimestampHandlerInterface) {
            $writeOnlyHandler = new StrictSessionHandler($writeOnlyHandler);
        }

        $this->currentHandler = $currentHandler;
        $this->writeOnlyHandler = $writeOnlyHandler;
    }

    /**
     * {@inheritdoc}
     */
    public function close()
    {
        $result = $this->currentHandler->close();
        $this->writeOnlyHandler->close();

        return $result;
    }

    /**
     * {@inheritdoc}
     */
    public function destroy($sessionId)
    {
        $result = $this->currentHandler->destroy($sessionId);
        $this->writeOnlyHandler->destroy($sessionId);

        return $result;
    }

    /**
     * {@inheritdoc}
     */
    public function gc($maxlifetime)
    {
        $result = $this->currentHandler->gc($maxlifetime);
        $this->writeOnlyHandler->gc($maxlifetime);

        return $result;
    }

    /**
     * {@inheritdoc}
     */
    public function open($savePath, $sessionName)
    {
        $result = $this->currentHandler->open($savePath, $sessionName);
        $this->writeOnlyHandler->open($savePath, $sessionName);

        return $result;
    }

    /**
     * {@inheritdoc}
     */
    public function read($sessionId)
    {
        // No reading from new handler until switch-over
        return $this->currentHandler->read($sessionId);
    }

    /**
     * {@inheritdoc}
     */
    public function write($sessionId, $sessionData)
    {
        $result = $this->currentHandler->write($sessionId, $sessionData);
        $this->writeOnlyHandler->write($sessionId, $sessionData);

        return $result;
    }

    /**
     * {@inheritdoc}
     */
    public function validateId($sessionId)
    {
        // No reading from new handler until switch-over
        return $this->currentHandler->validateId($sessionId);
    }

    /**
     * {@inheritdoc}
     */
    public function updateTimestamp($sessionId, $sessionData)
    {
        $result = $this->currentHandler->updateTimestamp($sessionId, $sessionData);
        $this->writeOnlyHandler->updateTimestamp($sessionId, $sessionData);

        return $result;
    }
}