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

Skip to content

Commit dee3768

Browse files
Merge branch '2.7' into 2.8
* 2.7: [HttpFoundation] Add test [HttpFoundation] Fix session-related BC break fix method name
2 parents 9f38c69 + 5fa5ef7 commit dee3768

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

src/Symfony/Component/Form/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* either as "Y-m-d" string or as timestamp. Internally we still want to
5151
* use a DateTime object for processing. To convert the data from string/integer
5252
* to DateTime you can set a normalization transformer by calling
53-
* addNormTransformer(). The normalized data is then converted to the displayed
53+
* addModelTransformer(). The normalized data is then converted to the displayed
5454
* data as described before.
5555
*
5656
* 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_VERSION_ID >= 50400 && \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
}
@@ -288,7 +283,7 @@ public function getBag($name)
288283
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
289284
}
290285

291-
if ($this->saveHandler->isActive() && !$this->started) {
286+
if (!$this->started && $this->saveHandler->isActive()) {
292287
$this->loadSession();
293288
} elseif (!$this->started) {
294289
$this->start();
@@ -336,7 +331,7 @@ public function isStarted()
336331
*/
337332
public function setOptions(array $options)
338333
{
339-
if (headers_sent()) {
334+
if (headers_sent() || (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status())) {
340335
return;
341336
}
342337

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

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

398+
if (headers_sent() || (\PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status())) {
399+
return;
400+
}
401+
407402
if ($this->saveHandler instanceof \SessionHandlerInterface) {
408403
if (\PHP_VERSION_ID >= 50400) {
409404
session_set_save_handler($this->saveHandler, false);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,19 @@ public function testSetSessionOptionsOnceSessionStartedIsIgnored()
296296
// Assert no exception has been thrown by `getStorage()`
297297
$this->addToAssertionCount(1);
298298
}
299+
300+
/**
301+
* @requires PHP 5.4
302+
*/
303+
public function testGetBagsOnceSessionStartedIsIgnored()
304+
{
305+
session_start();
306+
$bag = new AttributeBag();
307+
$bag->setName('flashes');
308+
309+
$storage = $this->getStorage();
310+
$storage->registerBag($bag);
311+
312+
$this->assertEquals($storage->getBag('flashes'), $bag);
313+
}
299314
}

0 commit comments

Comments
 (0)