Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b44a4b

Browse files
Merge branch '2.8' into 3.3
* 2.8: [HttpFoundation] Add test [HttpFoundation] Fix session-related BC break fix method name
2 parents 50c2a7c + dee3768 commit 1b44a4b

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/Symfony/Component/Form/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* either as "Y-m-d" string or as timestamp. Internally we still want to
5050
* use a DateTime object for processing. To convert the data from string/integer
5151
* to DateTime you can set a normalization transformer by calling
52-
* addNormTransformer(). The normalized data is then converted to the displayed
52+
* addModelTransformer(). The normalized data is then converted to the displayed
5353
* data as described before.
5454
*
5555
* The conversions (1) -> (2) -> (3) use the transform methods of the transformers.

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ class NativeSessionStorage implements SessionStorageInterface
102102
*/
103103
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
104104
{
105-
$this->setMetadataBag($metaBag);
106-
107-
if (\PHP_SESSION_ACTIVE === session_status()) {
108-
return;
109-
}
110-
111105
$options += array(
112106
// disable by default because it's managed by HeaderBag (if used)
113107
'cache_limiter' => '',
@@ -116,6 +110,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB
116110

117111
session_register_shutdown();
118112

113+
$this->setMetadataBag($metaBag);
119114
$this->setOptions($options);
120115
$this->setSaveHandler($handler);
121116
}
@@ -287,7 +282,7 @@ public function getBag($name)
287282
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
288283
}
289284

290-
if ($this->saveHandler->isActive() && !$this->started) {
285+
if (!$this->started && $this->saveHandler->isActive()) {
291286
$this->loadSession();
292287
} elseif (!$this->started) {
293288
$this->start();
@@ -335,7 +330,7 @@ public function isStarted()
335330
*/
336331
public function setOptions(array $options)
337332
{
338-
if (headers_sent()) {
333+
if (headers_sent() || \PHP_SESSION_ACTIVE === session_status()) {
339334
return;
340335
}
341336

@@ -390,10 +385,6 @@ public function setSaveHandler($saveHandler = null)
390385
throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
391386
}
392387

393-
if (headers_sent($file, $line)) {
394-
throw new \RuntimeException(sprintf('Failed to set the session handler because headers have already been sent by "%s" at line %d.', $file, $line));
395-
}
396-
397388
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
398389
if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
399390
$saveHandler = new SessionHandlerProxy($saveHandler);
@@ -402,6 +393,10 @@ public function setSaveHandler($saveHandler = null)
402393
}
403394
$this->saveHandler = $saveHandler;
404395

396+
if (headers_sent() || \PHP_SESSION_ACTIVE === session_status()) {
397+
return;
398+
}
399+
405400
if ($this->saveHandler instanceof \SessionHandlerInterface) {
406401
session_set_save_handler($this->saveHandler, false);
407402
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,16 @@ public function testSetSessionOptionsOnceSessionStartedIsIgnored()
262262
// Assert no exception has been thrown by `getStorage()`
263263
$this->addToAssertionCount(1);
264264
}
265+
266+
public function testGetBagsOnceSessionStartedIsIgnored()
267+
{
268+
session_start();
269+
$bag = new AttributeBag();
270+
$bag->setName('flashes');
271+
272+
$storage = $this->getStorage();
273+
$storage->registerBag($bag);
274+
275+
$this->assertEquals($storage->getBag('flashes'), $bag);
276+
}
265277
}

0 commit comments

Comments
 (0)