Changeset 358
- Timestamp:
- 03/10/07 00:13:56 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/util/stubRegistry.php
r152 r358 34 34 private final function __construct() 35 35 { 36 // nothing to do here36 // nothing to do here 37 37 } 38 38 … … 43 43 * @param mixed $value value to store 44 44 */ 45 public static function set($key, $value)46 {47 self::$registry[$key] = $value;48 }45 public static function set($key, $value) 46 { 47 self::$registry[$key] = $value; 48 } 49 49 50 50 /** … … 54 54 * @param mixed $value value to store 55 55 */ 56 public static function setConfig($key, $value)57 {58 self::$config[$key] = $value;59 }56 public static function setConfig($key, $value) 57 { 58 self::$config[$key] = $value; 59 } 60 60 61 61 /** … … 65 65 * @return bool true if a value exists under the given key, else false 66 66 */ 67 public static function has($key)68 {69 return isset(self::$registry[$key]);70 }67 public static function has($key) 68 { 69 return isset(self::$registry[$key]); 70 } 71 71 72 72 /** 73 73 * return the value stored under the given key, if key does not exist it returns null 74 74 * 75 * @param string $key key where the value is stored under 75 * @param string $key key where the value is stored under 76 * @param mixed $default optional default value to return if $key not set 76 77 * @return mixed 77 78 */ 78 public static function get($key)79 {80 if (isset(self::$registry[$key]) == true) {81 return self::$registry[$key];82 }83 84 return null;85 }86 79 public static function get($key, $default = null) 80 { 81 if (isset(self::$registry[$key]) == true) { 82 return self::$registry[$key]; 83 } 84 85 return $default; 86 } 87 87 88 /** 88 89 * check if a value exists under the given key … … 91 92 * @return bool true if a value exists under the given key for the given module, else false 92 93 */ 93 public static function hasConfig($key)94 {95 if (isset(self::$config[$key]) == true) {96 return true;97 }98 99 return false;100 }94 public static function hasConfig($key) 95 { 96 if (isset(self::$config[$key]) == true) { 97 return true; 98 } 99 100 return false; 101 } 101 102 102 103 /** 103 104 * return the value stored under the given key, if key in module does not exist it returns null 104 105 * 105 * @param string $key key where the value is stored under 106 * @param string $key key where the value is stored under 107 * @param mixed $default optional default value to return if $key not set 106 108 * @return mixed 107 109 */ 108 public static function getConfig($key)109 {110 if (isset(self::$config[$key]) == true) {111 return self::$config[$key];112 }113 114 return null;115 }110 public static function getConfig($key, $default = null) 111 { 112 if (isset(self::$config[$key]) == true) { 113 return self::$config[$key]; 114 } 115 116 return $default; 117 } 116 118 } 117 119 ?> trunk/src/test/php/net/stubbles/util/stubRegistryTestCase.php
r152 r358 19 19 * assure that values are returned as they are put into the registry 20 20 */ 21 public function testNormal() 22 { 23 $this->assertNull(stubRegistry::get('test')); 24 $this->assertFalse(stubRegistry::has('test')); 25 stubRegistry::set('test', 'test'); 26 $this->assertTrue(stubRegistry::has('test')); 27 $this->assertEqual(stubRegistry::get('test'), 'test'); 28 $test = new stdClass(); 29 stubRegistry::set('test', $test); 30 $this->assertTrue(stubRegistry::has('test')); 31 $regTest = stubRegistry::get('test'); 32 $this->assertReference($regTest, $test); 33 } 21 public function testNormal() 22 { 23 $this->assertNull(stubRegistry::get('test')); 24 $this->assertEqual(stubRegistry::get('test', 'foo'), 'foo'); 25 $this->assertFalse(stubRegistry::has('test')); 26 stubRegistry::set('test', 'test'); 27 $this->assertTrue(stubRegistry::has('test')); 28 $this->assertEqual(stubRegistry::get('test'), 'test'); 29 $test = new stdClass(); 30 stubRegistry::set('test', $test); 31 $this->assertTrue(stubRegistry::has('test')); 32 $regTest = stubRegistry::get('test'); 33 $this->assertReference($regTest, $test); 34 } 34 35 35 36 /** 36 37 * assure that values are returned as they are put into the config registry 37 38 */ 38 public function testConfig() 39 { 40 $this->assertNull(stubRegistry::getConfig('test')); 41 $this->assertFalse(stubRegistry::hasConfig('test')); 42 stubRegistry::setConfig('test', 'test'); 43 $this->assertTrue(stubRegistry::hasConfig('test')); 44 $this->assertEqual(stubRegistry::getConfig('test'), 'test'); 45 $test = new stdClass(); 46 stubRegistry::setConfig('test', $test); 47 $this->assertTrue(stubRegistry::hasConfig('test')); 48 $regTest = stubRegistry::getConfig('test'); 49 $this->assertReference($regTest, $test); 50 } 39 public function testConfig() 40 { 41 $this->assertNull(stubRegistry::getConfig('test')); 42 $this->assertEqual(stubRegistry::getConfig('test', 'foo'), 'foo'); 43 $this->assertFalse(stubRegistry::hasConfig('test')); 44 stubRegistry::setConfig('test', 'test'); 45 $this->assertTrue(stubRegistry::hasConfig('test')); 46 $this->assertEqual(stubRegistry::getConfig('test'), 'test'); 47 $test = new stdClass(); 48 stubRegistry::setConfig('test', $test); 49 $this->assertTrue(stubRegistry::hasConfig('test')); 50 $regTest = stubRegistry::getConfig('test'); 51 $this->assertReference($regTest, $test); 52 } 51 53 } 52 54 ?>
