Changeset 584
- Timestamp:
- 04/20/07 14:32:56 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ipo/interceptors/stubInterceptorXJConfInitializer.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/rdbms/stubDatabaseInitializer.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/util/log/stubLoggerXJConfFactory.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/util/stubRegistryXJConfInitializer.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfInitializer.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfProxy.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubProcessorResolverXJConfFactory.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/variantmanager/stubVariantXJConfFactory.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/xjconf/stubXJConfProxyTestCase.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/interceptors/stubInterceptorXJConfInitializer.php
r547 r584 109 109 110 110 /** 111 * returns a list of extensions for the parser 112 * 113 * @return array<Extension> 114 */ 115 public function getExtensions() 116 { 117 return array(); 118 } 119 120 /** 111 121 * will be called in case the stubXJConfProxy did not found the data in the 112 122 * cache and the initializer has to load values from the facade trunk/src/main/php/net/stubbles/rdbms/stubDatabaseInitializer.php
r538 r584 57 57 58 58 /** 59 * returns a list of extensions for the parser 60 * 61 * @return array<Extension> 62 */ 63 public function getExtensions() 64 { 65 return array(); 66 } 67 68 /** 59 69 * will be called in case the stubXJConfProxy did not found the data in the 60 70 * cache and the initializer has to load values from the facade trunk/src/main/php/net/stubbles/util/log/stubLoggerXJConfFactory.php
r562 r584 75 75 76 76 /** 77 * returns a list of extensions for the parser 78 * 79 * @return array<Extension> 80 */ 81 public function getExtensions() 82 { 83 return array(new stubConfigXJConfExtension()); 84 } 85 86 /** 77 87 * will be called in case the stubXJConfProxy did not found the data in the 78 88 * cache and the initializer has to load values from the facade … … 93 103 { 94 104 $xjconfProxy = new stubXJConfProxy($this); 95 $xjconfProxy->process( array(new stubConfigXJConfExtension()));105 $xjconfProxy->process(); 96 106 } 97 107 } trunk/src/main/php/net/stubbles/util/stubRegistryXJConfInitializer.php
r538 r584 57 57 58 58 /** 59 * returns a list of extensions for the parser 60 * 61 * @return array<Extension> 62 */ 63 public function getExtensions() 64 { 65 return array(); 66 } 67 68 /** 59 69 * will be called in case the stubXJConfProxy did not found the data in the 60 70 * cache and the initializer has to load values from the facade trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfInitializer.php
r538 r584 44 44 45 45 /** 46 * returns a list of extensions for the parser 47 * 48 * @return array<Extension> 49 */ 50 public function getExtensions(); 51 52 /** 46 53 * will be called in case the stubXJConfProxy did not found the data in the 47 54 * cache and the initializer has to load values from the facade trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfProxy.php
r580 r584 60 60 * initialize with configuration values from given configuration file 61 61 * 62 * @param array< Extension> a list of XJConf extensions62 * @param array<string> optional a list of sources to parse 63 63 * @return bool true if data was cached, else false 64 64 * @throws stubXJConfException 65 65 */ 66 public function process(array $ extensions = array())66 public function process(array $sources = array()) 67 67 { 68 if (file_exists($this->cacheFile) == true && filemtime($this->cacheFile) >= filemtime($this->configFile)) { 69 $this->initializer->setCacheData(unserialize(file_get_contents($this->cacheFile))); 70 return; 68 if (file_exists($this->cacheFile) == true) { 69 $useCache = true; 70 if (count($sources) == 0 && filemtime($this->cacheFile) < filemtime($this->configFile)) { 71 $useCache = false; 72 } elseif (count($sources) > 0) { 73 foreach ($sources as $source) { 74 if (filemtime($this->cacheFile) < filemtime($source)) { 75 $useCache = false; 76 } 77 } 78 } 79 80 if (true == $useCache) { 81 $this->initializer->setCacheData(unserialize(file_get_contents($this->cacheFile))); 82 return; 83 } 71 84 } 72 85 … … 75 88 $xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/' . $this->initializer->getDescriptor() . '.xml')); 76 89 $xjconf->enableXIncludes(); 77 foreach ($ extensionsas $extension) {90 foreach ($this->initializer->getExtensions() as $extension) { 78 91 $xjconf->addExtension($extension); 79 92 } 80 93 81 $xjconf->parse($this->configFile); 82 $this->initializer->loadData($xjconf); 94 if (count($sources) == 0) { 95 $xjconf->parse($this->configFile); 96 $this->initializer->loadData($xjconf); 97 } else { 98 foreach ($sources as $source) { 99 $xjconf->parse($source); 100 $this->initializer->loadData($xjconf); 101 } 102 } 103 83 104 file_put_contents($this->cacheFile, serialize($this->initializer->getCacheData())); 84 105 } trunk/src/main/php/net/stubbles/websites/processors/stubProcessorResolverXJConfFactory.php
r561 r584 57 57 58 58 /** 59 * returns a list of extensions for the parser 60 * 61 * @return array<Extension> 62 */ 63 public function getExtensions() 64 { 65 return array(); 66 } 67 68 /** 59 69 * will be called in case the stubXJConfProxy did not found the data in the 60 70 * cache and the initializer has to load values from the facade trunk/src/main/php/net/stubbles/websites/variantmanager/stubVariantXJConfFactory.php
r551 r584 72 72 73 73 /** 74 * returns a list of extensions for the parser 75 * 76 * @return array<Extension> 77 */ 78 public function getExtensions() 79 { 80 return array(); 81 } 82 83 /** 74 84 * will be called in case the stubXJConfProxy did not found the data in the 75 85 * cache and the initializer has to load values from the facade trunk/src/test/php/net/stubbles/util/xjconf/stubXJConfProxyTestCase.php
r580 r584 42 42 protected $configFile; 43 43 /** 44 * list of source files 45 * 46 * @var array<string> 47 */ 48 protected $sourceFiles = array(); 49 /** 44 50 * the cache file 45 51 * … … 65 71 $this->dir = dirname(__FILE__); 66 72 $this->configFile = $this->dir . '/config.xml'; 73 $this->sourceFiles = array($this->dir . '/config1.xml', $this->dir . '/config2.xml'); 67 74 $this->cacheFile = $this->dir . '/config.cache'; 68 75 $this->xjConfProxy = new stubXJConfProxy($this->xjConfInitializer, $this->dir, $this->dir); … … 73 80 <config name=\"net.stubbles.mode\" value=\"test\" /> 74 81 </xj:configuration>"); 82 file_put_contents($this->sourceFiles[0], "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?> 83 <xj:configuration 84 xmlns:xj=\"http://xjconf.net/XJConf\" 85 xmlns=\"http://stubbles.net/util/registry\"> 86 <config name=\"net.stubbles.mode\" value=\"test\" /> 87 </xj:configuration>"); 88 file_put_contents($this->sourceFiles[1], "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?> 89 <xj:configuration 90 xmlns:xj=\"http://xjconf.net/XJConf\" 91 xmlns=\"http://stubbles.net/util/registry\"> 92 <config name=\"net.stubbles.mode\" value=\"test\" /> 93 </xj:configuration>"); 75 94 } 76 95 … … 82 101 if (file_exists($this->configFile) == true) { 83 102 unlink($this->configFile); 103 } 104 105 foreach ($this->sourceFiles as $sourceFile) { 106 if (file_exists($sourceFile) == true) { 107 unlink($sourceFile); 108 } 84 109 } 85 110 … … 99 124 $this->xjConfInitializer->expectOnce('setCacheData', array(array('foo' => 'bar'))); 100 125 $this->xjConfInitializer->expectNever('getCacheData'); 126 $this->xjConfInitializer->expectNever('getExtensions'); 101 127 $this->xjConfProxy->process(); 128 } 129 130 /** 131 * assure that values are taken from cache is cache file is newer than source files 132 */ 133 public function testIsCachedAndCacheIsNewerWithSourceFiles() 134 { 135 file_put_contents($this->cacheFile, serialize(array('foo' => 'bar'))); 136 foreach ($this->sourceFiles as $sourceFile) { 137 touch($sourceFile, (time() - 100)); 138 } 139 touch($this->cacheFile, time()); 140 $this->xjConfInitializer->expectOnce('setCacheData', array(array('foo' => 'bar'))); 141 $this->xjConfInitializer->expectNever('getCacheData'); 142 $this->xjConfInitializer->expectNever('getExtensions'); 143 $this->xjConfProxy->process($this->sourceFiles); 102 144 } 103 145 … … 114 156 $this->xjConfInitializer->expectOnce('getCacheData'); 115 157 $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bar')); 158 $this->xjConfInitializer->setReturnValue('getExtensions', array()); 116 159 $this->xjConfProxy->process(); 117 160 $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bar')); … … 119 162 120 163 /** 164 * assure that values are taken from cache is cache file is newer than source files 165 */ 166 public function testIsCachedAndCacheIsOlderWithSourceFiles() 167 { 168 file_put_contents($this->cacheFile, serialize(array('foo' => 'bar'))); 169 foreach ($this->sourceFiles as $sourceFile) { 170 touch($sourceFile, (time())); 171 } 172 touch($this->cacheFile, time() - 100); 173 $this->xjConfInitializer->expectNever('setCacheData'); 174 $this->xjConfInitializer->expectCallcount('loadData', 2); 175 $this->xjConfInitializer->expectOnce('getCacheData'); 176 $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bar')); 177 $this->xjConfInitializer->setReturnValue('getExtensions', array()); 178 $this->xjConfProxy->process($this->sourceFiles); 179 $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bar')); 180 } 181 182 /** 121 183 * assure that values are created and cached if they were not cached before 122 184 */ … … 127 189 $this->xjConfInitializer->expectOnce('getCacheData'); 128 190 $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bum')); 191 $this->xjConfInitializer->setReturnValue('getExtensions', array()); 129 192 $this->xjConfProxy->process(); 130 193 $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bum')); 131 194 } 195 196 /** 197 * assure that values are created and cached if they were not cached before 198 */ 199 public function testIsNotCachedWithSourceFiles() 200 { 201 $this->xjConfInitializer->expectNever('setCacheData'); 202 $this->xjConfInitializer->expectCallcount('loadData', 2); 203 $this->xjConfInitializer->expectOnce('getCacheData'); 204 $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bum')); 205 $this->xjConfInitializer->setReturnValue('getExtensions', array()); 206 $this->xjConfProxy->process($this->sourceFiles); 207 $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bum')); 208 } 132 209 } 133 210 ?>
