[DoctrineBridge] Refactor session storage to handler.
This commit is contained in:
parent
a1c678ecd7
commit
a6a9280a3b
@ -1,9 +1,17 @@
|
|||||||
<?php
|
<?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\Bridge\Doctrine\HttpFoundation;
|
namespace Symfony\Bridge\Doctrine\HttpFoundation;
|
||||||
|
|
||||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||||
use Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage;
|
|
||||||
use Doctrine\DBAL\Driver\Connection;
|
use Doctrine\DBAL\Driver\Connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,7 +20,7 @@ use Doctrine\DBAL\Driver\Connection;
|
|||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||||
*/
|
*/
|
||||||
class DbalSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
class DbalSessionHandler implements \SessionHandlerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Connection
|
* @var Connection
|
||||||
@ -25,26 +33,19 @@ class DbalSessionStorage extends AbstractSessionStorage implements \SessionHandl
|
|||||||
private $tableName;
|
private $tableName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param Connection $con An instance of Connection.
|
* @param Connection $con An instance of Connection.
|
||||||
* @param string $tableName Table name.
|
* @param string $tableName Table name.
|
||||||
* @param array $options Session configuration options
|
|
||||||
*/
|
*/
|
||||||
public function __construct(Connection $con, $tableName = 'sessions', array $options = array())
|
public function __construct(Connection $con, $tableName = 'sessions')
|
||||||
{
|
{
|
||||||
$this->con = $con;
|
$this->con = $con;
|
||||||
$this->tableName = $tableName;
|
$this->tableName = $tableName;
|
||||||
|
|
||||||
parent::__construct($options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a session.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param string $path (ignored)
|
|
||||||
* @param string $name (ignored)
|
|
||||||
*
|
|
||||||
* @return Boolean true, if the session was opened, otherwise an exception is thrown
|
|
||||||
*/
|
*/
|
||||||
public function open($path = null, $name = null)
|
public function open($path = null, $name = null)
|
||||||
{
|
{
|
||||||
@ -52,9 +53,7 @@ class DbalSessionStorage extends AbstractSessionStorage implements \SessionHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes a session.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return Boolean true, if the session was closed, otherwise false
|
|
||||||
*/
|
*/
|
||||||
public function close()
|
public function close()
|
||||||
{
|
{
|
||||||
@ -63,13 +62,7 @@ class DbalSessionStorage extends AbstractSessionStorage implements \SessionHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroys a session.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param string $id A session ID
|
|
||||||
*
|
|
||||||
* @return Boolean true, if the session was destroyed, otherwise an exception is thrown
|
|
||||||
*
|
|
||||||
* @throws \RuntimeException If the session cannot be destroyed
|
|
||||||
*/
|
*/
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
@ -85,13 +78,7 @@ class DbalSessionStorage extends AbstractSessionStorage implements \SessionHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans up old sessions.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param int $lifetime The lifetime of a session
|
|
||||||
*
|
|
||||||
* @return Boolean true, if old sessions have been cleaned, otherwise an exception is thrown
|
|
||||||
*
|
|
||||||
* @throws \RuntimeException If any old sessions cannot be cleaned
|
|
||||||
*/
|
*/
|
||||||
public function gc($lifetime)
|
public function gc($lifetime)
|
||||||
{
|
{
|
||||||
@ -107,13 +94,7 @@ class DbalSessionStorage extends AbstractSessionStorage implements \SessionHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a session.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param string $id A session ID
|
|
||||||
*
|
|
||||||
* @return string The session data if the session was read or created, otherwise an exception is thrown
|
|
||||||
*
|
|
||||||
* @throws \RuntimeException If the session cannot be read
|
|
||||||
*/
|
*/
|
||||||
public function read($id)
|
public function read($id)
|
||||||
{
|
{
|
||||||
@ -136,14 +117,7 @@ class DbalSessionStorage extends AbstractSessionStorage implements \SessionHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes session data.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param string $id A session ID
|
|
||||||
* @param string $data A serialized chunk of session data
|
|
||||||
*
|
|
||||||
* @return Boolean true, if the session was written, otherwise an exception is thrown
|
|
||||||
*
|
|
||||||
* @throws \RuntimeException If the session data cannot be written
|
|
||||||
*/
|
*/
|
||||||
public function write($id, $data)
|
public function write($id, $data)
|
||||||
{
|
{
|
@ -1,5 +1,14 @@
|
|||||||
<?php
|
<?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\Bridge\Doctrine\HttpFoundation;
|
namespace Symfony\Bridge\Doctrine\HttpFoundation;
|
||||||
|
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
@ -9,7 +18,7 @@ use Doctrine\DBAL\Schema\Schema;
|
|||||||
*
|
*
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||||
*/
|
*/
|
||||||
final class DbalSessionStorageSchema extends Schema
|
final class DbalSessionHandlerSchema extends Schema
|
||||||
{
|
{
|
||||||
private $tableName;
|
private $tableName;
|
||||||
|
|
Reference in New Issue
Block a user