Changeset 526
- Timestamp:
- 04/14/07 21:13:10 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/util/stubRegistry.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/util/stubRegistryXJConfInitializer.php (modified) (5 diffs)
- trunk/src/test/php/net/stubbles/util/UtilTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/stubRegistryTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/util/stubRegistryXJConfInitializerTestCase.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/util/stubRegistry.php
r525 r526 3 3 * Class for storing values. 4 4 * 5 * @author Frank Kleine < frank@kl-s.com>5 * @author Frank Kleine <mikey@stubbles.net> 6 6 * @package stubbles 7 7 * @subpackage util trunk/src/main/php/net/stubbles/util/stubRegistryXJConfInitializer.php
r443 r526 3 3 * Class for initializing the Registry. 4 4 * 5 * @author Frank Kleine < frank@kl-s.com>5 * @author Frank Kleine <mikey@stubbles.net> 6 6 * @package stubbles 7 7 * @subpackage util 8 8 */ 9 9 stubClassLoader::load('net.stubbles.util.stubFactory', 10 'net.stubbles.util.stubRegistry', 10 11 'net.stubbles.util.stubRegistryInitializer', 11 12 'net.stubbles.util.xjconf.xjconf' … … 25 26 */ 26 27 protected $configFile; 27 28 /** 29 * name of the cache file to use 30 * 31 * @var string 32 */ 33 protected $cacheFile; 34 28 35 /** 29 36 * constructor … … 32 39 { 33 40 $this->configFile = stubConfig::getConfigPath() . '/xml/config.xml'; 41 $this->cacheFile = stubConfig::getCachePath() . '/config.cache'; 34 42 } 35 43 36 44 /** 37 * sets the name of the config gile to use45 * sets the name of the config file to use 38 46 * 39 47 * @param string $configFile … … 43 51 $this->configFile = $configFile; 44 52 } 45 53 46 54 /** 47 55 * initialize the Registry with configuration values from given configuration file … … 52 60 public function init() 53 61 { 54 $xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 62 if ($this->isCacheUpToDate() == true) { 63 foreach ($this->getCacheData() as $key => $value) { 64 stubRegistry::setConfig($key, $value); 65 } 66 67 return; 68 } 69 70 $xjconf = $this->createXJConfFacade(); 55 71 $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/registry.xml')); 56 72 $xjconf->enableXIncludes(); 57 73 $xjconf->parse($this->configFile); 74 $cacheData = array(); 75 foreach (stubRegistry::getConfigKeys() as $key) { 76 $cacheData[$key] = stubRegistry::getConfig($key); 77 } 78 79 $this->setCacheData($cacheData); 80 } 81 82 /** 83 * checks if the cache file is newer than the config file 84 * 85 * @return bool 86 */ 87 protected function isCacheUpToDate() 88 { 89 return (file_exists($this->cacheFile) == true && filemtime($this->cacheFile) >= filemtime($this->configFile)); 90 } 91 92 /** 93 * retrieves the cache data 94 * 95 * @return array 96 */ 97 protected function getCacheData() 98 { 99 return unserialize(file_get_contents($this->cacheFile)); 100 } 101 102 /** 103 * saves the cache data 104 * 105 * @param array<string,mixed> $cacheData 106 */ 107 protected function setCacheData(array $cacheData) 108 { 109 file_put_contents($this->cacheFile, serialize($cacheData)); 110 } 111 112 /** 113 * creates an instance of the XJConfFacade 114 * 115 * @return stubXJConfFacade 116 */ 117 protected function createXJConfFacade() 118 { 119 return new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance($this->configFile))); 58 120 } 59 121 } trunk/src/test/php/net/stubbles/util/UtilTestSuite.php
r426 r526 24 24 $this->addTestFile($dir . '/BinfordTestCase.php'); 25 25 $this->addTestFile($dir . '/stubRegistryTestCase.php'); 26 $this->addTestFile($dir . '/stubRegistryXJConfInitializerTestCase.php'); 26 27 27 28 // error handler trunk/src/test/php/net/stubbles/util/stubRegistryTestCase.php
r525 r526 1 1 <?php 2 2 /** 3 * Tests for helper.stubRegistry3 * Tests for net.stubbles.util.stubRegistry 4 4 * 5 5 * @author Frank Kleine <frank@kl-s.com> … … 9 9 stubClassLoader::load('net.stubbles.util.stubRegistry'); 10 10 /** 11 * Tests for helper.stubRegistry11 * Tests for net.stubbles.util.stubRegistry 12 12 * 13 13 * @package stubbles
