From cb7edb493a5d4d2dc1f3d818d36dc812132fb6aa Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 26 Nov 2006 00:08:23 +0000 Subject: [PATCH] Making the entire BSRegister class static --- Input.php | 8 ++--- Register.php | 70 +++++++++++++++++++-------------------- UnitTest/RegisterTest.php | 67 +++++++++++++++---------------------- 3 files changed, 66 insertions(+), 79 deletions(-) diff --git a/Input.php b/Input.php index be697e4..147e24c 100644 --- a/Input.php +++ b/Input.php @@ -109,8 +109,8 @@ class BSInput set_magic_quotes_runtime(0); // some debug info that's always useful - BSRegister::Instance()->debug('magic_quotes_gpc = ' . $this->magicquotes); - BSRegister::Instance()->debug('register_globals = ' . ini_get('register_globals')); + BSRegister::Debug('magic_quotes_gpc = ' . $this->magicquotes); + BSRegister::Debug('register_globals = ' . ini_get('register_globals')); $this->sanitizeInputData(); @@ -404,11 +404,11 @@ class BSInput trigger_error('No external hosts are allowed to POST to this application'); exit; } - BSRegister::Instance()->debug('remote post check = ok'); + BSRegister::Debug('remote post check = ok'); } else { - BSRegister::Instance()->debug('remote post check = FAILED'); + BSRegister::Debug('remote post check = FAILED'); } } } diff --git a/Register.php b/Register.php index 72048df..74f6039 100644 --- a/Register.php +++ b/Register.php @@ -131,7 +131,7 @@ class BSRegister * * @return object BSRegister instance */ - public static function Instance() + private static function Instance() { if (self::$instance == null) { @@ -147,9 +147,9 @@ class BSRegister * * @param string Application name */ - public function setApplication($name) + public static function SetApplication($name) { - $this->application = $name; + self::Instance()->application = $name; } // ################################################################### @@ -158,9 +158,9 @@ class BSRegister * * @return string Application name */ - public function getApplication() + public static function GetApplication() { - return $this->application; + return self::Instance()->application; } // ################################################################### @@ -169,9 +169,9 @@ class BSRegister * * @param string Path */ - public function setAppPath($path) + public static function SetAppPath($path) { - $this->appPath = BSFunctions::FetchSourcePath($path); + self::Instance()->appPath = BSFunctions::FetchSourcePath($path); } // ################################################################### @@ -180,9 +180,9 @@ class BSRegister * * @return string Application path */ - public function getAppPath() + public static function GetAppPath() { - return $this->appPath; + return self::Instance()->appPath; } // ################################################################### @@ -191,9 +191,9 @@ class BSRegister * * @param string Application version */ - public function setAppVersion($vers) + public static function SetAppVersion($vers) { - $this->appVersion = $vers; + self::Instance()->appVersion = $vers; } // ################################################################### @@ -202,9 +202,9 @@ class BSRegister * * @return string Application version */ - public function getAppVersion() + public static function GetAppVersion() { - return $this->appVersion; + return self::Instance()->appVersion; } // ################################################################### @@ -214,9 +214,9 @@ class BSRegister * * @param string Path */ - public function setWebPath($path) + public static function SetWebPath($path) { - $this->webPath = BSFunctions::FetchSourcePath($path); + self::Instance()->webPath = BSFunctions::FetchSourcePath($path); } // ################################################################### @@ -225,9 +225,9 @@ class BSRegister * * @return string Application's web path */ - public function getWebPath() + public static function GetWebPath() { - return $this->webPath; + return self::Instance()->webPath; } // ################################################################### @@ -236,9 +236,9 @@ class BSRegister * * @param bool Debug mode on? */ - public function setDebug($debug) + public static function SetDebug($debug) { - $this->debug = $debug; + self::Instance()->debug = $debug; } // ################################################################### @@ -247,9 +247,9 @@ class BSRegister * * @return bool Debug mode on? */ - public function getDebug() + public static function GetDebug() { - return $this->debug; + return self::Instance()->debug; } // ################################################################### @@ -260,15 +260,15 @@ class BSRegister * @param string Registry key * @param mixed Value to register */ - public function register($key, $value) + public static function Register($key, $value) { - if (isset($this->registry["$key"])) + if (isset(self::Instance()->registry["$key"])) { trigger_error('Cannot overwrite a key in the registry'); return; } - $this->registry["$key"] = $value; + self::Instance()->registry["$key"] = $value; } // ################################################################### @@ -278,15 +278,15 @@ class BSRegister * * @param string Registry key */ - public function unregister($key) + public static function Unregister($key) { - if (!isset($this->registry["$key"])) + if (!isset(self::Instance()->registry["$key"])) { trigger_error('You cannot unregister a key that does not exist'); return; } - unset($this->registry["$key"]); + unset(self::Instance()->registry["$key"]); } // ################################################################### @@ -297,15 +297,15 @@ class BSRegister * * @return mixed Value in the registry for key */ - public function get($key) + public static function Get($key) { - if (!isset($this->registry["$key"])) + if (!isset(self::Instance()->registry["$key"])) { trigger_error('Cannot access the registry with a non-existent key'); return; } - return $this->registry["$key"]; + return self::Instance()->registry["$key"]; } // ################################################################### @@ -314,9 +314,9 @@ class BSRegister * * @return array Complete registry */ - public function getAll() + public static function GetAll() { - return $this->registry; + return self::Instance()->registry; } // ################################################################### @@ -326,11 +326,11 @@ class BSRegister * * @param string Debug message */ - public function debug($msg) + public static function Debug($msg) { - if ($this->debug) + if (self::Instance()->debug) { - $this->debugInfo[] = $msg; + self::Instance()->debugInfo[] = $msg; } } diff --git a/UnitTest/RegisterTest.php b/UnitTest/RegisterTest.php index 0de7f60..3cbf00f 100644 --- a/UnitTest/RegisterTest.php +++ b/UnitTest/RegisterTest.php @@ -13,20 +13,7 @@ require_once('./../Register.php'); * */ class RegisterTest extends UnitTestCase -{ - protected $fixture; - - public function setUp() - { - $this->fixture = BSRegister::Instance(); - } - - public function testNewRegister() - { - $this->assertTrue($this->fixture instanceof BSRegister); - $this->assertReference($this->fixture, BSRegister::Instance()); - } - +{ public function testLoadModule() { $this->assertTrue(BSRegister::LoadModule('Input') instanceof BSInput); @@ -40,82 +27,82 @@ class RegisterTest extends UnitTestCase public function testSetGetAppPath() { - $this->fixture->setAppPath(getcwd()); - $this->assertEqual(getcwd() . DIRECTORY_SEPARATOR, $this->fixture->getAppPath()); + BSRegister::SetAppPath(getcwd()); + $this->assertEqual(getcwd() . DIRECTORY_SEPARATOR, BSRegister::GetAppPath()); } public function testSetGetAppVersion() { - $this->fixture->setAppVersion('1.0-test'); - $this->assertEqual('1.0-test', $this->fixture->getAppVersion()); + BSRegister::SetAppVersion('1.0-test'); + $this->assertEqual('1.0-test', BSRegister::GetAppVersion()); } public function testSetGetApplication() { - $this->fixture->setApplication('ISSO Tests'); - $this->assertEqual('ISSO Tests', $this->fixture->getApplication()); + BSRegister::SetApplication('ISSO Tests'); + $this->assertEqual('ISSO Tests', BSRegister::GetApplication()); } public function testSetGetWebPath() { $path = DIRECTORY_SEPARATOR . 'Server' . DIRECTORY_SEPARATOR . 'htdocs' . DIRECTORY_SEPARATOR . 'ISSO'; - $this->fixture->setWebPath($path); - $this->assertEqual($path . DIRECTORY_SEPARATOR, $this->fixture->getWebPath()); + BSRegister::SetWebPath($path); + $this->assertEqual($path . DIRECTORY_SEPARATOR, BSRegister::GetWebPath()); } public function testSetGetDebug() { - $this->fixture->setDebug(true); - $this->assertIdentical(true, $this->fixture->getDebug()); + BSRegister::SetDebug(true); + $this->assertIdentical(true, BSRegister::GetDebug()); } public function testRegisterValue() { - $this->fixture->register('someKey', 'someValue'); + BSRegister::Register('someKey', 'someValue'); - $registry = $this->fixture->getAll(); + $registry = BSRegister::GetAll(); $this->assertEqual($registry['someKey'], 'someValue'); } public function testGetAll() { - $this->fixture->register('test', 1); - $this->assertIsA($this->fixture->getAll(), 'array'); - $this->assertEqual(sizeof($this->fixture->getAll()), 2); + BSRegister::Register('test', 1); + $this->assertIsA(BSRegister::GetAll(), 'array'); + $this->assertEqual(sizeof(BSRegister::GetAll()), 2); } public function testOverWriteRegister() { - $this->fixture->register('valueToOverWrite', 1); - $this->fixture->register('valueToOverWrite', 2); + BSRegister::Register('valueToOverWrite', 1); + BSRegister::Register('valueToOverWrite', 2); $this->assertError(); - $this->assertEqual(1, $this->fixture->get('valueToOverWrite')); + $this->assertEqual(1, BSRegister::Get('valueToOverWrite')); } public function testGet() { - $this->fixture->register('testGet', 123); - $this->assertEqual(123, $this->fixture->get('testGet')); + BSRegister::Register('testGet', 123); + $this->assertEqual(123, BSRegister::Get('testGet')); } public function testUnregister() { - $this->fixture->register('testUnregister', 1); - $this->fixture->unregister('testUnregister'); - $this->fixture->register('testUnregister', 2); + BSRegister::Register('testUnregister', 1); + BSRegister::Unregister('testUnregister'); + BSRegister::Register('testUnregister', 2); $this->assertNoErrors(); - $this->assertEqual(2, $this->fixture->get('testUnregister')); + $this->assertEqual(2, BSRegister::Get('testUnregister')); } public function testGetNoExist() { - $this->fixture->get('doesNotExist'); + BSRegister::Get('doesNotExist'); $this->assertError(); } public function testUnregisterNoExist() { - $this->fixture->unregister('keyThatWontExist'); + BSRegister::Unregister('keyThatWontExist'); $this->assertError(); } } -- 2.43.5