-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[HttpFoundation] Refactor session handling and flash messages #2714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
a2a8024
[FrameworkBundle] Refactor tests.
f21cfda
[HttpFoundation] Added structured namespacing to session attributes.
d20a1a0
[HttpFoundation] Move flash messages out of Session class and change …
04c5a3a
[HttpFoundation] Introduce a SessionInterface to make session class m…
202bde1
[HttpFoundation] Refactored the FlashBag* changing the way old messag…
6e4ee80
[BC Break][HttpFoundation] Refactored session handling to be true to …
f8ed4d8
[HttpFoundation] Added some new Native*Storage drivers for SQLite and…
e970caa
[HttpFoundation] SessionID is passed by PHP.
5920b69
[HttpFoundation] Add MemcacheSessionStorage driver.
006df6b
[HttpFoundation] Add MemcachedSessionStorage driver.
fe5fb53
[HttpFoundation] Added prefix to storage keys and declared properties.
e415277
[HttpFoundation] Documentation.
c2625c2
[BC Break][FrameworkBundle] Fix unit tests in.
5b15138
[HttpFoundation] Cleaned up constants.
58bc557
[HttpFoundation] remove test, needs to be completely re-written.
fe7bc8d
[HttpFoundation] Refactor test.
13f59b8
[WebProfilerBundle] Removed hack to make flash messages persist for a…
3340eaf
[Security] Refactor session storage driver in test.
e624746
[HttpFoundation] Added NullSessionStorage
402c3bd
[FrameworkBundle] Update session configuration XML.
1083d32
[HttpFoundation] Added native memcached session storage driver.
07dba61
[HttpFoundation] Correct callback names.
37455f3
[HttpFoundation] Remove check for now to allow tests to pass.
51f06a7
[TwigBundle] Refactor test for session management.
efadac3
[HttpFoundation][FrameworkBundle][SecurityBundle] Make parameters con…
af52d9e
Updated changelog and upgrading documentation.
f66987a
[HttpFoundation] FlashBag docblocks and class constants.
d6f779c
[HttpFoundation][FrameworkBundle] FilsyststemSessionStorage drive is …
967eb54
Coding standards, docblocks.
597b400
Typo.
22cd77c
Simplified examples of how to show flash messages.
de9f6df
[HttpFoundation] Add simple flash-message API to SessionInterface.
27383ac
[HttpFoundation] Change attribute namespacing character.
6f3135f
[HttpFoundation] Fix docblock return value.
be6810c
[Bridge/HttpFoundation] Refactored DbalSessionStorage
aee6c8a
[HttpFoundation] Typo fix.
9b0e1df
[HttpFoundation][FrameworkBundle] Moved session attributes to it's ow…
8498d7e
[HttpFoundation][FrameworkBundle] Made configuration of session stora…
3cc1f7e
[HttpFoundation] Allow session.cache_limiter to be forced if really r…
ccb1696
[HttpFoundation] Fix sprintf() calls.
044dca4
Documentation, coding standards and docblocks.
e89a82c
[HttpFoundation][FrameworkBundle][TwigBundle][Bridge/Doctrine] Move b…
eee89d6
[HttpFoundation][FrameworkBundle][SecurityBundle] Introduced mock ses…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HttpFoundation] Documentation.
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,82 +79,6 @@ public function __construct(FlashBagInterface $flashBag, array $options = array( | |
$this->registerShutdownFunction(); | ||
} | ||
|
||
/** | ||
* Sets the session.* ini variables. | ||
* | ||
* @param array $options | ||
*/ | ||
protected function setOptions(array $options) | ||
{ | ||
$cookieDefaults = session_get_cookie_params(); | ||
$this->options = array_merge(array( | ||
'lifetime' => $cookieDefaults['lifetime'], | ||
'path' => $cookieDefaults['path'], | ||
'domain' => $cookieDefaults['domain'], | ||
'secure' => $cookieDefaults['secure'], | ||
'httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false, | ||
), $options); | ||
|
||
// See session.* for values at http://www.php.net/manual/en/ini.list.php | ||
foreach ($this->options as $key => $value) { | ||
ini_set('session.'.$key, $value); | ||
} | ||
} | ||
|
||
/** | ||
* Registers this storage device for PHP session handling. | ||
* | ||
* If you need this method, please call it during the __construct() of this driver. | ||
* | ||
* PHP requires session save handlers. There are some defaults set automatically | ||
* when PHP starts, but these can be overriden using this command if you need anything | ||
* other than PHP's default handling. | ||
* | ||
* When the session starts, PHP will call the sessionRead() handler which should return an array | ||
* of any session attributes. PHP will then populate these into $_SESSION. | ||
* | ||
* When PHP shuts down, the sessionWrite() handler is called and will pass the $_SESSION contents | ||
* to be stored. | ||
* | ||
* When a session is specifically destroyed, PHP will call the sessionDestroy() handler with the | ||
* session ID. This happens when the session is regenerated for example and th handler | ||
* MUST delete the session by ID from the persistent storage immediately. | ||
* | ||
* PHP will call sessionGc() from time to time to expire any session records according to the | ||
* set max lifetime of a session. This routine should delete all records from persistent | ||
* storage which were last accessed longer than the $lifetime. | ||
* | ||
* PHP sessionOpen() and sessionClose() are pretty much redundant and can return true. | ||
* | ||
* @see http://php.net/manual/en/function.session-set-save-handler.php | ||
*/ | ||
protected function registerSaveHandlers() | ||
{ | ||
// note this can be reset to PHP's control using ini_set('session.save_handler', 'files'); | ||
// so long as ini_set() is called before the session is started. | ||
if ($this instanceof SessionSaveHandlerInterface) { | ||
session_set_save_handler( | ||
array($this, 'open'), | ||
array($this, 'close'), | ||
array($this, 'read'), | ||
array($this, 'write'), | ||
array($this, 'destroy'), | ||
array($this, 'gc') | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Registers PHP shutdown function. | ||
* | ||
* This methos is required to avoid strange issues when using PHP objects as | ||
* session save handlers. | ||
*/ | ||
protected function registerShutdownFunction() | ||
{ | ||
register_shutdown_function('session_write_close'); | ||
} | ||
|
||
/** | ||
* Gets the flashbag. | ||
* | ||
|
@@ -216,7 +140,6 @@ public function getId() | |
{ | ||
if (!$this->started) { | ||
return ''; // returning empty is consistent with session_id() behaviour | ||
//throw new \RuntimeException('The session has not been started'); | ||
} | ||
|
||
return session_id(); | ||
|
@@ -367,12 +290,91 @@ public function clear() | |
* an anonymous session to a logged in user session. | ||
* | ||
* @param boolean $destroy | ||
* | ||
* @return boolean Returns true on success or false on failure. | ||
*/ | ||
public function regenerate($destroy = false) | ||
{ | ||
return session_regenerate_id($destroy); | ||
} | ||
|
||
/** | ||
* Sets the session.* ini variables. | ||
* | ||
* Note we omit session. from the beginning of the keys. | ||
* | ||
* @param array $options | ||
*/ | ||
protected function setOptions(array $options) | ||
{ | ||
$cookieDefaults = session_get_cookie_params(); | ||
$this->options = array_merge(array( | ||
'lifetime' => $cookieDefaults['lifetime'], | ||
'path' => $cookieDefaults['path'], | ||
'domain' => $cookieDefaults['domain'], | ||
'secure' => $cookieDefaults['secure'], | ||
'httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false, | ||
), $options); | ||
|
||
// See session.* for values at http://www.php.net/manual/en/ini.list.php | ||
foreach ($this->options as $key => $value) { | ||
ini_set('session.'.$key, $value); | ||
} | ||
} | ||
|
||
/** | ||
* Registers this storage device for PHP session handling. | ||
* | ||
* PHP requires session save handlers to be set, either it's own, or custom ones. | ||
* There are some defaults set automatically when PHP starts, but these can be overriden | ||
* using this command if you need anything other than PHP's default handling. | ||
* | ||
* When the session starts, PHP will call the sessionRead() handler which should return an array | ||
* of any session attributes. PHP will then populate these into $_SESSION. | ||
* | ||
* When PHP shuts down, the sessionWrite() handler is called and will pass the $_SESSION contents | ||
* to be stored. | ||
* | ||
* When a session is specifically destroyed, PHP will call the sessionDestroy() handler with the | ||
* session ID. This happens when the session is regenerated for example and th handler | ||
* MUST delete the session by ID from the persistent storage immediately. | ||
* | ||
* PHP will call sessionGc() from time to time to expire any session records according to the | ||
* set max lifetime of a session. This routine should delete all records from persistent | ||
* storage which were last accessed longer than the $lifetime. | ||
* | ||
* PHP sessionOpen() and sessionClose() are pretty much redundant and can just return true. | ||
* | ||
* @see http://php.net/manual/en/function.session-set-save-handler.php | ||
* @see SessionSaveHandlerInterface | ||
*/ | ||
protected function registerSaveHandlers() | ||
{ | ||
// note this can be reset to PHP's control using ini_set('session.save_handler', 'files'); | ||
// so long as ini_set() is called before the session is started. | ||
if ($this instanceof SessionSaveHandlerInterface) { | ||
session_set_save_handler( | ||
array($this, 'open'), | ||
array($this, 'close'), | ||
array($this, 'read'), | ||
array($this, 'write'), | ||
array($this, 'destroy'), | ||
array($this, 'gc') | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Registers PHP shutdown function. | ||
* | ||
* This methos is required to avoid strange issues when using PHP objects as | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo here. should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected. |
||
* session save handlers. | ||
*/ | ||
protected function registerShutdownFunction() | ||
{ | ||
register_shutdown_function('session_write_close'); | ||
} | ||
|
||
/** | ||
* Resolves a path in attributes property and returns it as a reference. | ||
* | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo