Skip to content

Commit 524bf84

Browse files
committed
[HttpFoundation] update phpdoc of SessionHandlerInterface and unify parameters of all handlers according to interface
1 parent ccdfbe6 commit 524bf84

File tree

9 files changed

+52
-89
lines changed

9 files changed

+52
-89
lines changed

src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
* DBAL based session storage.
2727
*
2828
* This implementation is very similar to Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
29-
* but uses the Doctrine driver connection interface for non-PDO-based drivers like mysqli or OCI8.
30-
* It is recommended to use the wrapper Doctrine\DBAL\Connection for lazy connections and optimized database-specific queries.
29+
* but uses the Doctrine driver connection interface and thus also works with non-PDO-based drivers like mysqli and OCI8.
3130
*
3231
* @author Fabien Potencier <fabien@symfony.com>
3332
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
@@ -63,7 +62,7 @@ class DbalSessionHandler implements \SessionHandlerInterface
6362
/**
6463
* Constructor.
6564
*
66-
* @param DriverConnection $con A driver connection, preferably a wrapper Doctrine\DBAL\Connection
65+
* @param DriverConnection $con A driver connection, preferably a wrapper Doctrine\DBAL\Connection for lazy connections
6766
* @param string $tableName Table name
6867
*/
6968
public function __construct(DriverConnection $con, $tableName = 'sessions')

src/Symfony/Component/HttpFoundation/Resources/stubs/SessionHandlerInterface.php

+21-31
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
*/
1111

1212
/**
13-
* SessionHandlerInterface
14-
*
15-
* Provides forward compatibility with PHP 5.4
13+
* SessionHandlerInterface for PHP < 5.4
1614
*
1715
* Extensive documentation can be found at php.net, see links:
1816
*
@@ -25,76 +23,68 @@
2523
interface SessionHandlerInterface
2624
{
2725
/**
28-
* Open session.
26+
* Re-initializes existing session, or creates a new one.
2927
*
3028
* @see http://php.net/sessionhandlerinterface.open
3129
*
32-
* @param string $savePath Save path.
33-
* @param string $sessionName Session Name.
34-
*
35-
* @throws \RuntimeException If something goes wrong starting the session.
30+
* @param string $savePath Save path
31+
* @param string $sessionName Session name, see http://php.net/function.session-name.php
3632
*
37-
* @return bool
33+
* @return bool true on success, false on failure
3834
*/
3935
public function open($savePath, $sessionName);
4036

4137
/**
42-
* Close session.
38+
* Closes the current session.
4339
*
4440
* @see http://php.net/sessionhandlerinterface.close
4541
*
46-
* @return bool
42+
* @return bool true on success, false on failure
4743
*/
4844
public function close();
4945

5046
/**
51-
* Read session.
52-
*
53-
* @param string $sessionId
47+
* Reads the session data.
5448
*
5549
* @see http://php.net/sessionhandlerinterface.read
5650
*
57-
* @throws \RuntimeException On fatal error but not "record not found".
51+
* @param string $sessionId Session ID, see http://php.net/function.session-id
5852
*
59-
* @return string String as stored in persistent storage or empty string in all other cases.
53+
* @return string Same session data as passed in write() or empty string when non-existent or on failure
6054
*/
6155
public function read($sessionId);
6256

6357
/**
64-
* Commit session to storage.
58+
* Writes the session data to the storage.
6559
*
6660
* @see http://php.net/sessionhandlerinterface.write
6761
*
68-
* @param string $sessionId Session ID.
69-
* @param string $data Session serialized data to save.
62+
* @param string $sessionId Session ID , see http://php.net/function.session-id
63+
* @param string $data Serialized session data to save
7064
*
71-
* @return bool
65+
* @return bool true on success, false on failure
7266
*/
7367
public function write($sessionId, $data);
7468

7569
/**
76-
* Destroys this session.
70+
* Destroys a session.
7771
*
7872
* @see http://php.net/sessionhandlerinterface.destroy
7973
*
80-
* @param string $sessionId Session ID.
74+
* @param string $sessionId Session ID, see http://php.net/function.session-id
8175
*
82-
* @throws \RuntimeException On fatal error.
83-
*
84-
* @return bool
76+
* @return bool true on success, false on failure
8577
*/
8678
public function destroy($sessionId);
8779

8880
/**
89-
* Garbage collection for storage.
81+
* Cleans up expired sessions (garbage collection).
9082
*
9183
* @see http://php.net/sessionhandlerinterface.gc
9284
*
93-
* @param int $lifetime Max lifetime in seconds to keep sessions stored.
94-
*
95-
* @throws \RuntimeException On fatal error.
85+
* @param string|int $maxlifetime Sessions that have not updated for the last maxlifetime seconds will be removed
9686
*
97-
* @return bool
87+
* @return bool true on success, false on failure
9888
*/
99-
public function gc($lifetime);
89+
public function gc($maxlifetime);
10090
}

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcacheSessionHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function destroy($sessionId)
101101
/**
102102
* {@inheritdoc}
103103
*/
104-
public function gc($lifetime)
104+
public function gc($maxlifetime)
105105
{
106106
// not required here because memcache will auto expire the records anyhow.
107107
return true;

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function destroy($sessionId)
107107
/**
108108
* {@inheritdoc}
109109
*/
110-
public function gc($lifetime)
110+
public function gc($maxlifetime)
111111
{
112112
// not required here because memcached will auto expire the records anyhow.
113113
return true;

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function destroy($sessionId)
9999
/**
100100
* {@inheritdoc}
101101
*/
102-
public function gc($lifetime)
102+
public function gc($maxlifetime)
103103
{
104104
/* Note: MongoDB 2.2+ supports TTL collections, which may be used in
105105
* place of this method by indexing the "time_field" field with an
@@ -109,7 +109,7 @@ public function gc($lifetime)
109109
*
110110
* See: http://docs.mongodb.org/manual/tutorial/expire-data/
111111
*/
112-
$time = new \MongoDate(time() - $lifetime);
112+
$time = new \MongoDate(time() - $maxlifetime);
113113

114114
$this->getCollection()->remove(array(
115115
$this->options['time_field'] => array('$lt' => $time),

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NullSessionHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function destroy($sessionId)
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
public function gc($lifetime)
68+
public function gc($maxlifetime)
6969
{
7070
return true;
7171
}

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function __construct(\PDO $pdo, array $dbOptions = array())
8383
/**
8484
* {@inheritdoc}
8585
*/
86-
public function open($path, $name)
86+
public function open($savePath, $sessionName)
8787
{
8888
return true;
8989
}
@@ -99,14 +99,14 @@ public function close()
9999
/**
100100
* {@inheritdoc}
101101
*/
102-
public function destroy($id)
102+
public function destroy($sessionId)
103103
{
104104
// delete the record associated with this id
105105
$sql = "DELETE FROM $this->table WHERE $this->idCol = :id";
106106

107107
try {
108108
$stmt = $this->pdo->prepare($sql);
109-
$stmt->bindParam(':id', $id, \PDO::PARAM_STR);
109+
$stmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
110110
$stmt->execute();
111111
} catch (\PDOException $e) {
112112
throw new \RuntimeException(sprintf('PDOException was thrown when trying to delete a session: %s', $e->getMessage()), 0, $e);
@@ -118,14 +118,14 @@ public function destroy($id)
118118
/**
119119
* {@inheritdoc}
120120
*/
121-
public function gc($lifetime)
121+
public function gc($maxlifetime)
122122
{
123123
// delete the session records that have expired
124124
$sql = "DELETE FROM $this->table WHERE $this->timeCol < :time";
125125

126126
try {
127127
$stmt = $this->pdo->prepare($sql);
128-
$stmt->bindValue(':time', time() - $lifetime, \PDO::PARAM_INT);
128+
$stmt->bindValue(':time', time() - $maxlifetime, \PDO::PARAM_INT);
129129
$stmt->execute();
130130
} catch (\PDOException $e) {
131131
throw new \RuntimeException(sprintf('PDOException was thrown when trying to delete expired sessions: %s', $e->getMessage()), 0, $e);
@@ -137,13 +137,13 @@ public function gc($lifetime)
137137
/**
138138
* {@inheritdoc}
139139
*/
140-
public function read($id)
140+
public function read($sessionId)
141141
{
142142
$sql = "SELECT $this->dataCol FROM $this->table WHERE $this->idCol = :id";
143143

144144
try {
145145
$stmt = $this->pdo->prepare($sql);
146-
$stmt->bindParam(':id', $id, \PDO::PARAM_STR);
146+
$stmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
147147
$stmt->execute();
148148

149149
// We use fetchAll instead of fetchColumn to make sure the DB cursor gets closed
@@ -162,7 +162,7 @@ public function read($id)
162162
/**
163163
* {@inheritdoc}
164164
*/
165-
public function write($id, $data)
165+
public function write($sessionId, $data)
166166
{
167167
// Session data can contain non binary safe characters so we need to encode it.
168168
$encoded = base64_encode($data);
@@ -175,7 +175,7 @@ public function write($id, $data)
175175

176176
if (null !== $mergeSql) {
177177
$mergeStmt = $this->pdo->prepare($mergeSql);
178-
$mergeStmt->bindParam(':id', $id, \PDO::PARAM_STR);
178+
$mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
179179
$mergeStmt->bindParam(':data', $encoded, \PDO::PARAM_STR);
180180
$mergeStmt->bindValue(':time', time(), \PDO::PARAM_INT);
181181
$mergeStmt->execute();
@@ -189,13 +189,13 @@ public function write($id, $data)
189189
$deleteStmt = $this->pdo->prepare(
190190
"DELETE FROM $this->table WHERE $this->idCol = :id"
191191
);
192-
$deleteStmt->bindParam(':id', $id, \PDO::PARAM_STR);
192+
$deleteStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
193193
$deleteStmt->execute();
194194

195195
$insertStmt = $this->pdo->prepare(
196196
"INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time)"
197197
);
198-
$insertStmt->bindParam(':id', $id, \PDO::PARAM_STR);
198+
$insertStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
199199
$insertStmt->bindParam(':data', $encoded, \PDO::PARAM_STR);
200200
$insertStmt->bindValue(':time', time(), \PDO::PARAM_INT);
201201
$insertStmt->execute();

src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,25 @@ public function close()
6464
/**
6565
* {@inheritdoc}
6666
*/
67-
public function read($id)
67+
public function read($sessionId)
6868
{
69-
return (string) $this->handler->read($id);
69+
return (string) $this->handler->read($sessionId);
7070
}
7171

7272
/**
7373
* {@inheritdoc}
7474
*/
75-
public function write($id, $data)
75+
public function write($sessionId, $data)
7676
{
77-
return (bool) $this->handler->write($id, $data);
77+
return (bool) $this->handler->write($sessionId, $data);
7878
}
7979

8080
/**
8181
* {@inheritdoc}
8282
*/
83-
public function destroy($id)
83+
public function destroy($sessionId)
8484
{
85-
return (bool) $this->handler->destroy($id);
85+
return (bool) $this->handler->destroy($sessionId);
8686
}
8787

8888
/**

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

+7-33
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
1313

14+
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
15+
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
1416
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
17+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
1518
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
16-
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
17-
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
1819
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy;
1920
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
2021

@@ -175,9 +176,9 @@ public function testSetSaveHandler53()
175176
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy', $storage->getSaveHandler());
176177
$storage->setSaveHandler(new NativeSessionHandler());
177178
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy', $storage->getSaveHandler());
178-
$storage->setSaveHandler(new SessionHandlerProxy(new SessionHandler()));
179+
$storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler()));
179180
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
180-
$storage->setSaveHandler(new SessionHandler());
181+
$storage->setSaveHandler(new NullSessionHandler());
181182
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
182183
$storage->setSaveHandler(new NativeProxy());
183184
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy', $storage->getSaveHandler());
@@ -199,9 +200,9 @@ public function testSetSaveHandler54()
199200
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
200201
$storage->setSaveHandler(new NativeSessionHandler());
201202
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
202-
$storage->setSaveHandler(new SessionHandlerProxy(new SessionHandler()));
203+
$storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler()));
203204
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
204-
$storage->setSaveHandler(new SessionHandler());
205+
$storage->setSaveHandler(new NullSessionHandler());
205206
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
206207
}
207208

@@ -254,30 +255,3 @@ public function testCanStartOutside54()
254255
$storage->start();
255256
}
256257
}
257-
258-
class SessionHandler implements \SessionHandlerInterface
259-
{
260-
public function open($savePath, $sessionName)
261-
{
262-
}
263-
264-
public function close()
265-
{
266-
}
267-
268-
public function read($id)
269-
{
270-
}
271-
272-
public function write($id, $data)
273-
{
274-
}
275-
276-
public function destroy($id)
277-
{
278-
}
279-
280-
public function gc($maxlifetime)
281-
{
282-
}
283-
}

0 commit comments

Comments
 (0)