From 5ac62a5b918b267e0cf85690b687012ad17b5dbb Mon Sep 17 00:00:00 2001 From: Andjelko Horvat <comel@vingd.com> Date: Fri, 11 Nov 2011 09:27:05 +0000 Subject: [PATCH] SimpleSAML_Auth_State: add cloneState function (issue 451). git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2979 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/Auth/State.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/SimpleSAML/Auth/State.php b/lib/SimpleSAML/Auth/State.php index c1bfdb630..5eb1b555e 100644 --- a/lib/SimpleSAML/Auth/State.php +++ b/lib/SimpleSAML/Auth/State.php @@ -37,6 +37,13 @@ class SimpleSAML_Auth_State { const ID = 'SimpleSAML_Auth_State.id'; + /** + * The index in the cloned state array which contains the identifier of the + * original state. + */ + const CLONE_ORIGINAL_ID = 'SimpleSAML_Auth_State.cloneOriginalId'; + + /** * The index in the state array which contains the current stage. */ @@ -162,6 +169,30 @@ class SimpleSAML_Auth_State { } + /** + * Clone the state. + * + * This function clones and returns the new cloned state. + * + * @param array $state The original request state. + * @return array Cloned state data. + */ + public static function cloneState(array $state) { + $clonedState = $state; + + if (array_key_exists(self::ID, $state)) { + $clonedState[self::CLONE_ORIGINAL_ID] = $state[self::ID]; + unset($clonedState[self::ID]); + + SimpleSAML_Logger::debug('Cloned state: ' . var_export($state[self::ID], TRUE)); + } else { + SimpleSAML_Logger::debug('Cloned state with undefined id.'); + } + + return $clonedState; + } + + /** * Retrieve saved state. * -- GitLab