From 4c2ff4bd0ad117cc33a9da7e55bfce475bd6d42d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 15 Oct 2010 02:50:43 +0000 Subject: [PATCH] APICHANGE: refactored methods in session to use coding conventions (from r105756) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112502 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/Session.php | 36 ++++++++++++++++++++++++++++++++++-- forms/Form.php | 2 +- tests/SessionTest.php | 4 ++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/core/Session.php b/core/Session.php index b3c49c947..683fb4f9e 100644 --- a/core/Session.php +++ b/core/Session.php @@ -66,7 +66,19 @@ class Session { } } + /** + * @deprecated 2.5 Use Session::add_to_array($name, $val) instead + */ public static function addToArray($name, $val) { + user_error('Session::addToArray() is deprecated. Please use Session::add_to_array() instead.', E_USER_NOTICE); + + return Session::add_to_array($name, $val); + } + + /** + * Add a value to a specific key in the session array + */ + public static function add_to_array($name, $val) { return Controller::curr()->getSession()->inst_addToArray($name, $val); } @@ -91,9 +103,20 @@ class Session { /** * Return all the values in session + * + * @return Array + */ + public static function get_all() { + return Controller::curr()->getSession()->inst_getAll(); + } + + /** + * @deprecated 2.5 Use Session::get_all() */ public static function getAll() { - return Controller::curr()->getSession()->inst_getAll(); + user_error('Session::getAll() is deprecated. Please use Session::get_all() instead.', E_USER_NOTICE); + + return Session::get_all(); } /** @@ -108,10 +131,19 @@ class Session { /** * Clear all the values */ - public static function clearAll() { + public static function clear_all() { return Controller::curr()->getSession()->inst_clearAll(); } + /** + * @deprecated 2.5 Use Session::clear_all() + */ + public static function clearAll() { + user_error('Session::clearAll() is deprecated. Please use Session::clear_all() instead.', E_USER_NOTICE); + + return Session::clear_all(); + } + /** * Save all the values in our session to $_SESSION */ diff --git a/forms/Form.php b/forms/Form.php index 75c54e70f..74559863a 100755 --- a/forms/Form.php +++ b/forms/Form.php @@ -358,7 +358,7 @@ class Form extends RequestHandler { * and used the next time this form is displayed. */ function addErrorMessage($fieldName, $message, $messageType) { - Session::addToArray("FormInfo.{$this->FormName()}.errors", array( + Session::add_to_array("FormInfo.{$this->FormName()}.errors", array( 'fieldName' => $fieldName, 'message' => $message, 'messageType' => $messageType, diff --git a/tests/SessionTest.php b/tests/SessionTest.php index fd85fb007..0d9de4781 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -26,7 +26,7 @@ class SessionTest extends SapphireTest { Session::set('Test', 'Test'); Session::set('Test-1', 'Test-1'); - Session::clearAll(); + Session::clear_all(); // should session get return null? The array key should probably be // unset from the data array @@ -38,7 +38,7 @@ class SessionTest extends SapphireTest { Session::set('Test', 'Test'); Session::set('Test-2', 'Test-2'); - $session = Session::getAll(); + $session = Session::get_all(); $this->assertEquals($session, array('Test' => 'Test', 'Test-2' => 'Test-2')); }