Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bb30a44

Browse filesBrowse files
author
Drak
committed
[HttpFoundation] Prepare to split out session handler callback from session storage.
1 parent e01106f commit bb30a44
Copy full SHA for bb30a44

File tree

Expand file treeCollapse file tree

4 files changed

+242
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+242
-0
lines changed
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
13+
14+
/**
15+
* Adds SessionHandler functionality if available.
16+
*
17+
* @see http://php.net/sessionhandler
18+
*/
19+
20+
if (version_compare(phpversion(), '5.4.0', '>=')) {
21+
class NativeSessionHandler extends \SessionHandler {}
22+
} else {
23+
class NativeSessionHandler {}
24+
}
+80Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
13+
14+
/**
15+
* AbstractProxy.
16+
*/
17+
abstract class AbstractProxy
18+
{
19+
/**
20+
* Flag if handler wraps an internal PHP session handler (using \SessionHandler).
21+
*
22+
* @var boolean
23+
*/
24+
protected $wrapper = false;
25+
26+
/**
27+
* @var boolean
28+
*/
29+
protected $active = false;
30+
31+
/**
32+
* @var string
33+
*/
34+
protected $saveHandlerName;
35+
36+
/**
37+
* Gets the session.save_handler name.
38+
*
39+
* @return string
40+
*/
41+
public function getSaveHandlerName()
42+
{
43+
return $this->saveHandlerName;
44+
}
45+
46+
public function isSessionHandlerInterface()
47+
{
48+
return (bool)($this instanceof \SessionHandlerInterface);
49+
}
50+
51+
/**
52+
* Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
53+
*
54+
* @return bool
55+
*/
56+
public function isWrapper()
57+
{
58+
return $this->wrapper;
59+
}
60+
61+
/**
62+
* Has a session started?
63+
*
64+
* @return bool
65+
*/
66+
public function isActive()
67+
{
68+
return $this->active;
69+
}
70+
71+
/**
72+
* Sets the active flag.
73+
*
74+
* @param bool $flag
75+
*/
76+
public function setActive($flag)
77+
{
78+
$this->active = (bool)$flag;
79+
}
80+
}
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
13+
14+
/**
15+
* NativeProxy.
16+
*
17+
* This proxy is built-in session handlers in PHP 5.3.x
18+
*/
19+
class NativeProxy extends AbstractProxy
20+
{
21+
/**
22+
* Constructor.
23+
*
24+
* @param $handler
25+
*/
26+
public function __construct($handler)
27+
{
28+
if (version_compare(phpversion(), '5.4.0', '>=') && $handler instanceof \SessionHandlerInterface) {
29+
throw new \InvalidArgumentException('This proxy is only for PHP 5.3 and not for instances of \SessionHandler or \SessionHandlerInterface');
30+
}
31+
32+
$this->handler = $handler;
33+
$this->saveHandlerName = ini_get('session.save_handler');
34+
}
35+
36+
/**
37+
* Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
38+
*
39+
* @return bool False.
40+
*/
41+
public function isWrapper()
42+
{
43+
return false;
44+
}
45+
}
+93Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
13+
14+
/**
15+
* SessionHandler proxy.
16+
*/
17+
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
18+
{
19+
/**
20+
* @var \SessionHandlerInterface
21+
*/
22+
protected $handler;
23+
24+
/**
25+
* Constructor.
26+
*
27+
* @param \SessionHandlerInterface $handler
28+
*/
29+
public function __construct(\SessionHandlerInterface $handler)
30+
{
31+
$this->handler = $handler;
32+
$this->wrapper = (bool)(class_exists('SessionHandler') && $handler instanceof \SessionHandler);
33+
$this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') : 'user';
34+
}
35+
36+
// \SessionHandlerInterface
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
function open($savePath, $sessionName)
42+
{
43+
$return = (bool)$this->handler->open($savePath, $sessionName);
44+
45+
if (true === $return) {
46+
$this->active = true;
47+
}
48+
49+
return $return;
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
function close()
56+
{
57+
$this->active = false;
58+
59+
return (bool)$this->handler->close();
60+
}
61+
62+
/**
63+
* {@inheritdoc}
64+
*/
65+
function read($id)
66+
{
67+
return (string)$this->handler->read($id);
68+
}
69+
70+
/**
71+
* {@inheritdoc}
72+
*/
73+
function write($id, $data)
74+
{
75+
return (bool)$this->handler->write($id, $data);
76+
}
77+
78+
/**
79+
* {@inheritdoc}
80+
*/
81+
function destroy($id)
82+
{
83+
return (bool)$this->handler->destroy($id);
84+
}
85+
86+
/**
87+
* {@inheritdoc}
88+
*/
89+
function gc($maxlifetime)
90+
{
91+
return (bool)$this->handler->gc($maxlifetime);
92+
}
93+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.