Making Security a static class.

Fixing static access issues in test case.
This commit is contained in:
Mark Story 2010-04-23 21:28:54 -04:00
parent 33bfe0e5e2
commit 84002687c8
2 changed files with 7 additions and 36 deletions

View file

@ -24,7 +24,7 @@
* @package cake
* @subpackage cake.cake.libs
*/
class Security extends Object {
class Security {
/**
* Default hash method
@ -32,22 +32,7 @@ class Security extends Object {
* @var string
* @access public
*/
public $hashType = null;
/**
* Singleton implementation to get object instance.
*
* @return object
* @access public
* @static
*/
function &getInstance() {
static $instance = array();
if (!$instance) {
$instance[0] =& new Security;
}
return $instance[0];
}
public static $hashType = null;
/**
* Get allowed minutes of inactivity based on security level.
@ -111,8 +96,6 @@ class Security extends Object {
* @static
*/
public static function hash($string, $type = null, $salt = false) {
$_this =& Security::getInstance();
if ($salt) {
if (is_string($salt)) {
$string = $salt . $string;
@ -122,7 +105,7 @@ class Security extends Object {
}
if (empty($type)) {
$type = $_this->hashType;
$type = self::$hashType;
}
$type = strtolower($type);
@ -155,8 +138,7 @@ class Security extends Object {
* @see Security::hash()
*/
public static function setHash($hash) {
$_this =& Security::getInstance();
$_this->hashType = $hash;
self::$hashType = $hash;
}
/**

View file

@ -35,16 +35,6 @@ class SecurityTest extends CakeTestCase {
*/
public $sut = null;
/**
* setUp method
*
* @access public
* @return void
*/
function setUp() {
$this->sut =& Security::getInstance();
}
/**
* testInactiveMins method
*
@ -90,8 +80,7 @@ class SecurityTest extends CakeTestCase {
* @return void
*/
function testHash() {
$Security =& Security::getInstance();
$_hashType = $Security->hashType;
$_hashType = Security::$hashType;
$key = 'someKey';
$hash = 'someHash';
@ -109,7 +98,7 @@ class SecurityTest extends CakeTestCase {
$hashType = 'sha1';
Security::setHash($hashType);
$this->assertIdentical($this->sut->hashType, $hashType);
$this->assertIdentical(Security::$hashType, $hashType);
$this->assertIdentical(strlen(Security::hash($key, null, true)), 40);
$this->assertIdentical(strlen(Security::hash($key, null, false)), 40);
@ -118,7 +107,7 @@ class SecurityTest extends CakeTestCase {
$hashType = 'md5';
Security::setHash($hashType);
$this->assertIdentical($this->sut->hashType, $hashType);
$this->assertIdentical(Security::$hashType, $hashType);
$this->assertIdentical(strlen(Security::hash($key, null, false)), 32);
$this->assertIdentical(strlen(Security::hash($key, null, true)), 32);