Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitbb30a44

Browse files
author
Drak
committed
[HttpFoundation] Prepare to split out session handler callback from session storage.
1 parente01106f commitbb30a44

File tree

4 files changed

+242
-0
lines changed

4 files changed

+242
-0
lines changed
Lines 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+
namespaceSymfony\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 NativeSessionHandlerextends \SessionHandler {}
22+
}else {
23+
class NativeSessionHandler {}
24+
}
Lines 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+
namespaceSymfony\Component\HttpFoundation\Session\Storage\Proxy;
13+
14+
/**
15+
* AbstractProxy.
16+
*/
17+
abstractclass 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+
publicfunctiongetSaveHandlerName()
42+
{
43+
return$this->saveHandlerName;
44+
}
45+
46+
publicfunctionisSessionHandlerInterface()
47+
{
48+
return (bool)($thisinstanceof \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+
publicfunctionisWrapper()
57+
{
58+
return$this->wrapper;
59+
}
60+
61+
/**
62+
* Has a session started?
63+
*
64+
* @return bool
65+
*/
66+
publicfunctionisActive()
67+
{
68+
return$this->active;
69+
}
70+
71+
/**
72+
* Sets the active flag.
73+
*
74+
* @param bool $flag
75+
*/
76+
publicfunctionsetActive($flag)
77+
{
78+
$this->active = (bool)$flag;
79+
}
80+
}
Lines 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+
namespaceSymfony\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 NativeProxyextends AbstractProxy
20+
{
21+
/**
22+
* Constructor.
23+
*
24+
* @param $handler
25+
*/
26+
publicfunction__construct($handler)
27+
{
28+
if (version_compare(phpversion(),'5.4.0','>=') &&$handlerinstanceof \SessionHandlerInterface) {
29+
thrownew \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+
publicfunctionisWrapper()
42+
{
43+
returnfalse;
44+
}
45+
}
Lines 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+
namespaceSymfony\Component\HttpFoundation\Session\Storage\Proxy;
13+
14+
/**
15+
* SessionHandler proxy.
16+
*/
17+
class SessionHandlerProxyextends AbstractProxyimplements \SessionHandlerInterface
18+
{
19+
/**
20+
* @var \SessionHandlerInterface
21+
*/
22+
protected$handler;
23+
24+
/**
25+
* Constructor.
26+
*
27+
* @param \SessionHandlerInterface $handler
28+
*/
29+
publicfunction__construct(\SessionHandlerInterface$handler)
30+
{
31+
$this->handler =$handler;
32+
$this->wrapper = (bool)(class_exists('SessionHandler') &&$handlerinstanceof \SessionHandler);
33+
$this->saveHandlerName =$this->wrapper ?ini_get('session.save_handler') :'user';
34+
}
35+
36+
// \SessionHandlerInterface
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
functionopen($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+
functionclose()
56+
{
57+
$this->active =false;
58+
59+
return (bool)$this->handler->close();
60+
}
61+
62+
/**
63+
* {@inheritdoc}
64+
*/
65+
functionread($id)
66+
{
67+
return (string)$this->handler->read($id);
68+
}
69+
70+
/**
71+
* {@inheritdoc}
72+
*/
73+
functionwrite($id,$data)
74+
{
75+
return (bool)$this->handler->write($id,$data);
76+
}
77+
78+
/**
79+
* {@inheritdoc}
80+
*/
81+
functiondestroy($id)
82+
{
83+
return (bool)$this->handler->destroy($id);
84+
}
85+
86+
/**
87+
* {@inheritdoc}
88+
*/
89+
functiongc($maxlifetime)
90+
{
91+
return (bool)$this->handler->gc($maxlifetime);
92+
}
93+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp