Skip to content

Commit 8400268

Browse files
committed
Making Security a static class.
Fixing static access issues in test case.
1 parent 33bfe0e commit 8400268

File tree

2 files changed

+7
-36
lines changed

2 files changed

+7
-36
lines changed

cake/libs/security.php

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,15 @@
2424
* @package cake
2525
* @subpackage cake.cake.libs
2626
*/
27-
class Security extends Object {
27+
class Security {
2828

2929
/**
3030
* Default hash method
3131
*
3232
* @var string
3333
* @access public
3434
*/
35-
public $hashType = null;
36-
37-
/**
38-
* Singleton implementation to get object instance.
39-
*
40-
* @return object
41-
* @access public
42-
* @static
43-
*/
44-
function &getInstance() {
45-
static $instance = array();
46-
if (!$instance) {
47-
$instance[0] =& new Security;
48-
}
49-
return $instance[0];
50-
}
35+
public static $hashType = null;
5136

5237
/**
5338
* Get allowed minutes of inactivity based on security level.
@@ -111,8 +96,6 @@ function validateAuthKey($authKey) {
11196
* @static
11297
*/
11398
public static function hash($string, $type = null, $salt = false) {
114-
$_this =& Security::getInstance();
115-
11699
if ($salt) {
117100
if (is_string($salt)) {
118101
$string = $salt . $string;
@@ -122,7 +105,7 @@ public static function hash($string, $type = null, $salt = false) {
122105
}
123106

124107
if (empty($type)) {
125-
$type = $_this->hashType;
108+
$type = self::$hashType;
126109
}
127110
$type = strtolower($type);
128111

@@ -155,8 +138,7 @@ public static function hash($string, $type = null, $salt = false) {
155138
* @see Security::hash()
156139
*/
157140
public static function setHash($hash) {
158-
$_this =& Security::getInstance();
159-
$_this->hashType = $hash;
141+
self::$hashType = $hash;
160142
}
161143

162144
/**

cake/tests/cases/libs/security.test.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ class SecurityTest extends CakeTestCase {
3535
*/
3636
public $sut = null;
3737

38-
/**
39-
* setUp method
40-
*
41-
* @access public
42-
* @return void
43-
*/
44-
function setUp() {
45-
$this->sut =& Security::getInstance();
46-
}
47-
4838
/**
4939
* testInactiveMins method
5040
*
@@ -90,8 +80,7 @@ function testValidateAuthKey() {
9080
* @return void
9181
*/
9282
function testHash() {
93-
$Security =& Security::getInstance();
94-
$_hashType = $Security->hashType;
83+
$_hashType = Security::$hashType;
9584

9685
$key = 'someKey';
9786
$hash = 'someHash';
@@ -109,7 +98,7 @@ function testHash() {
10998

11099
$hashType = 'sha1';
111100
Security::setHash($hashType);
112-
$this->assertIdentical($this->sut->hashType, $hashType);
101+
$this->assertIdentical(Security::$hashType, $hashType);
113102
$this->assertIdentical(strlen(Security::hash($key, null, true)), 40);
114103
$this->assertIdentical(strlen(Security::hash($key, null, false)), 40);
115104

@@ -118,7 +107,7 @@ function testHash() {
118107

119108
$hashType = 'md5';
120109
Security::setHash($hashType);
121-
$this->assertIdentical($this->sut->hashType, $hashType);
110+
$this->assertIdentical(Security::$hashType, $hashType);
122111
$this->assertIdentical(strlen(Security::hash($key, null, false)), 32);
123112
$this->assertIdentical(strlen(Security::hash($key, null, true)), 32);
124113

0 commit comments

Comments
 (0)