Making the entire BSRegister class static
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 26 Nov 2006 00:08:23 +0000 (00:08 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 26 Nov 2006 00:08:23 +0000 (00:08 +0000)
Input.php
Register.php
UnitTest/RegisterTest.php

index be697e48481edac44268bd622a20fc250ff4ee41..147e24cc30def887e0f61a1d4f03342cf76bd03c 100644 (file)
--- 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');
                        }
                }
        }
index 72048dfc076e3776459fe7f834dca742e959248d..74f60398e1e4f14a9a167cdb13a7a1076f20b0ed 100644 (file)
@@ -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;
                }
        }
        
index 0de7f6054c59ea178810cc2b378b4c2b3b3a3e4d..3cbf00f1b152039d74cf8367059daa527a258b7a 100644 (file)
@@ -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();
        }
 }