Merge branch '2.7' into 2.8
* 2.7: [HttpFoundation] Add test [HttpFoundation] Fix session-related BC break fix method name
This commit is contained in:
commit
dee37688ab
@ -50,7 +50,7 @@ use Symfony\Component\PropertyAccess\PropertyPath;
|
|||||||
* either as "Y-m-d" string or as timestamp. Internally we still want to
|
* either as "Y-m-d" string or as timestamp. Internally we still want to
|
||||||
* use a DateTime object for processing. To convert the data from string/integer
|
* use a DateTime object for processing. To convert the data from string/integer
|
||||||
* to DateTime you can set a normalization transformer by calling
|
* to DateTime you can set a normalization transformer by calling
|
||||||
* addNormTransformer(). The normalized data is then converted to the displayed
|
* addModelTransformer(). The normalized data is then converted to the displayed
|
||||||
* data as described before.
|
* data as described before.
|
||||||
*
|
*
|
||||||
* The conversions (1) -> (2) -> (3) use the transform methods of the transformers.
|
* The conversions (1) -> (2) -> (3) use the transform methods of the transformers.
|
||||||
|
@ -102,12 +102,6 @@ class NativeSessionStorage implements SessionStorageInterface
|
|||||||
*/
|
*/
|
||||||
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
|
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
|
||||||
{
|
{
|
||||||
$this->setMetadataBag($metaBag);
|
|
||||||
|
|
||||||
if (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$options += array(
|
$options += array(
|
||||||
// disable by default because it's managed by HeaderBag (if used)
|
// disable by default because it's managed by HeaderBag (if used)
|
||||||
'cache_limiter' => '',
|
'cache_limiter' => '',
|
||||||
@ -116,6 +110,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
|||||||
|
|
||||||
session_register_shutdown();
|
session_register_shutdown();
|
||||||
|
|
||||||
|
$this->setMetadataBag($metaBag);
|
||||||
$this->setOptions($options);
|
$this->setOptions($options);
|
||||||
$this->setSaveHandler($handler);
|
$this->setSaveHandler($handler);
|
||||||
}
|
}
|
||||||
@ -288,7 +283,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
|||||||
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
|
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->saveHandler->isActive() && !$this->started) {
|
if (!$this->started && $this->saveHandler->isActive()) {
|
||||||
$this->loadSession();
|
$this->loadSession();
|
||||||
} elseif (!$this->started) {
|
} elseif (!$this->started) {
|
||||||
$this->start();
|
$this->start();
|
||||||
@ -336,7 +331,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
|||||||
*/
|
*/
|
||||||
public function setOptions(array $options)
|
public function setOptions(array $options)
|
||||||
{
|
{
|
||||||
if (headers_sent()) {
|
if (headers_sent() || (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,10 +386,6 @@ class NativeSessionStorage implements SessionStorageInterface
|
|||||||
throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
|
throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headers_sent($file, $line)) {
|
|
||||||
throw new \RuntimeException(sprintf('Failed to set the session handler because headers have already been sent by "%s" at line %d.', $file, $line));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
|
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
|
||||||
if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
|
if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
|
||||||
$saveHandler = new SessionHandlerProxy($saveHandler);
|
$saveHandler = new SessionHandlerProxy($saveHandler);
|
||||||
@ -404,6 +395,10 @@ class NativeSessionStorage implements SessionStorageInterface
|
|||||||
}
|
}
|
||||||
$this->saveHandler = $saveHandler;
|
$this->saveHandler = $saveHandler;
|
||||||
|
|
||||||
|
if (headers_sent() || (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->saveHandler instanceof \SessionHandlerInterface) {
|
if ($this->saveHandler instanceof \SessionHandlerInterface) {
|
||||||
if (\PHP_VERSION_ID >= 50400) {
|
if (\PHP_VERSION_ID >= 50400) {
|
||||||
session_set_save_handler($this->saveHandler, false);
|
session_set_save_handler($this->saveHandler, false);
|
||||||
|
@ -296,4 +296,19 @@ class NativeSessionStorageTest extends TestCase
|
|||||||
// Assert no exception has been thrown by `getStorage()`
|
// Assert no exception has been thrown by `getStorage()`
|
||||||
$this->addToAssertionCount(1);
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 5.4
|
||||||
|
*/
|
||||||
|
public function testGetBagsOnceSessionStartedIsIgnored()
|
||||||
|
{
|
||||||
|
session_start();
|
||||||
|
$bag = new AttributeBag();
|
||||||
|
$bag->setName('flashes');
|
||||||
|
|
||||||
|
$storage = $this->getStorage();
|
||||||
|
$storage->registerBag($bag);
|
||||||
|
|
||||||
|
$this->assertEquals($storage->getBag('flashes'), $bag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user