Changeset 580
- Timestamp:
- 04/20/07 00:47:12 (1 year ago)
- Files:
-
- trunk/lib/xjconf.star (modified) (previous)
- trunk/src/main/php/net/stubbles/ipo/request/stubRequestValueErrorXJConfFactory.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/util/xjconf/stubConfigXJConfExtension.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfClassLoader.php (added)
- trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfFacade.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfLoader.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfProxy.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/util/xjconf/xjconf.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/util/xjconf/xjconfReal.php (added)
- trunk/src/main/php/net/stubbles/websites/processors/stubJsonRpcProcessor.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/stubPageFactory.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/stubPageXJConfFactory.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/util/xjconf/stubXJConfProxyTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/websites/stubFrontControllerProcessTestCase.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/request/stubRequestValueErrorXJConfFactory.php
r446 r580 10 10 'net.stubbles.ipo.request.stubRequestValueErrorException', 11 11 'net.stubbles.util.stubFactory', 12 'net.stubbles.util.xjconf.xjconf' 12 'net.stubbles.util.xjconf.xjconf', 13 'net.stubbles.util.xjconf.xjconfReal' 13 14 ); 14 15 /** … … 37 38 if (null == self::$requestValueErrors) { 38 39 self::$requestValueErrors = array(); 39 $xjconf = new stubXJConfFacade( array('__default' => stubXJConfLoader::getInstance()));40 $xjconf-> parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/request.xml'));40 $xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance()))); 41 $xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/request.xml')); 41 42 $sources = stubFactory::getResourceURIs('ipo/request.xml'); 42 43 foreach ($sources as $source) { trunk/src/main/php/net/stubbles/util/xjconf/stubConfigXJConfExtension.php
r312 r580 7 7 * @subpackage util_xjconf 8 8 */ 9 stubClassLoader::load('net.stubbles.util.xjconf.xjconf'); 10 XJConfLoader::load('ext.Extension'); 9 stubClassLoader::load('net.xjconf.ext.Extension'); 11 10 /** 12 11 * Extension for XJConf to load values from stubConfig. trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfFacade.php
r446 r580 1 1 <?php 2 2 /** 3 * Facade for XJConf.3 * Decorator arround the facade for XJConf. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 7 7 * @subpackage util_xjconf 8 8 */ 9 stubClassLoader::load('net.stubbles.util.xjconf.xjconf');10 XJConfLoader::load('DefinitionParser',11 'XmlParser'12 );13 9 /** 14 * Facade for XJConf.10 * Decorator arround the facade for XJConf. 15 11 * 16 12 * @package stubbles … … 20 16 { 21 17 /** 22 * list of class loaders to use18 * the real facade 23 19 * 24 * @var array<string,XJConfClassLoader>20 * @var XJConfFacade 25 21 */ 26 protected $classLoaders = array(); 27 /** 28 * list of extensions to use 29 * 30 * @var array<string,Extension> 31 */ 32 protected $extensions = array(); 33 /** 34 * list of namespace definitions to merge with default one 35 * 36 * @var array<NamespaceDefinition> 37 */ 38 protected $namespaceDefinitions = array(); 39 /** 40 * the definition parser 41 * 42 * @var DefinitionParser 43 */ 44 protected $definitionParser; 45 /** 46 * the xml parser 47 * 48 * @var XmlParser 49 */ 50 protected $xmlParser; 51 22 protected $realFacade; 23 52 24 /** 53 25 * construct the facade 54 26 * 55 * @param array $classLoaders<string,XJConfClassLoader> optional list of class loaders for given namespaces27 * @param XJConfFacade $realFacade the real facade 56 28 */ 57 public function __construct( array $classLoaders = array())29 public function __construct($realFacade) 58 30 { 59 $this-> classLoaders = $classLoaders;31 $this->realFacade = $realFacade; 60 32 } 61 33 62 34 /** 63 * add an extension that handles all tags in given namespace35 * call interceptor 64 36 * 65 * @param Extension $ext use this extension to handle all tags in given namespace 66 * @param string $namespace optional handle all tags in this namespace with given extension 67 */ 68 public function addExtension(Extension $ext, $namespace = null) 69 { 70 if (null == $namespace) { 71 $namespace = $ext->getNamespace(); 72 } 73 74 $this->extensions[$namespace] = $ext; 75 } 76 77 /** 78 * enables xinclude 79 */ 80 public function enableXIncludes() 81 { 82 XJConfLoader::load('ext.xinc.XInclude'); 83 $xincludeExtension = new XInclude(); 84 $this->addExtension($xincludeExtension); 85 } 86 87 /** 88 * add a namespace definition 89 * 90 * @param NamespaceDefinition $namespaceDefinition 91 */ 92 public function addNamespaceDefinition(NamespaceDefinition $namespaceDefinition) 93 { 94 $this->namespaceDefinitions[$namespaceDefinition->getNamespaceURI()] = $namespaceDefinition; 95 } 96 97 /** 98 * add a namespace definition 99 * 100 * @param NamespaceDefinitions $namespaceDefinitions 101 */ 102 public function addNamespaceDefinitions(NamespaceDefinitions $namespaceDefinitions) 103 { 104 $this->namespaceDefinitions = array_merge($this->namespaceDefinitions, $namespaceDefinitions->getDefinedNamespaces()); 105 } 106 107 /** 108 * parses a definition and returns the namespace definitions 109 * 110 * @param string $definitionFile 111 * @return NamespaceDefinitions 112 */ 113 public function parseDefinition($definitionFile) 114 { 115 if (null == $this->definitionParser) { 116 $this->definitionParser = new DefinitionParser($this->classLoaders); 117 } 118 119 return $this->definitionParser->parse($definitionFile); 120 } 121 122 /** 123 * parses a definition file and adds its definitions 124 * 125 * @param string $definitionFile 126 */ 127 public function parseAndAddDefinition($definitionFile) 128 { 129 $this->addNamespaceDefinitions($this->parseDefinition($definitionFile)); 130 } 131 132 /** 133 * parses a definition file and adds its definitions 134 * 135 * @param array $definitions 136 */ 137 public function parseAndAddDefinitions(array $definitions) 138 { 139 foreach ($definitions as $definition) { 140 $this->addNamespaceDefinitions($this->parseDefinition($definition)); 141 } 142 } 143 144 /** 145 * parses a given file and creates the data structure described in this file 146 * 147 * @param string $filename 148 * @throws stubXJConfException 149 */ 150 public function parse($filename) 151 { 152 if (null == $this->xmlParser) { 153 $this->xmlParser = new XmlParser(); 154 } 155 156 $namespaceDefinitions = new NamespaceDefinitions(); 157 foreach ($this->namespaceDefinitions as $namespaceURI => $namespaceDefintion) { 158 $namespaceDefinitions->addNamespaceDefinition($namespaceURI, $namespaceDefintion); 159 } 160 $this->xmlParser->setTagDefinitions($namespaceDefinitions); 161 foreach ($this->extensions as $namespace => $extension) { 162 $this->xmlParser->addExtension($extension, $namespace); 163 } 164 165 try { 166 $this->xmlParser->parse($filename); 167 } catch (XJConfException $xjce) { 168 throw new stubXJConfException('Could not parse ' . $filename, $xjce); 169 } 170 } 171 172 /** 173 * checks whether a data structure associated with this name exists 174 * 175 * @param string $name 176 * @return bool 177 * @throws stubXJConfException 178 */ 179 public function hasConfigValue($name) 180 { 181 if (null == $this->xmlParser) { 182 throw new stubXJConfException('Invalid state: needs to parse first.'); 183 } 184 185 return $this->xmlParser->hasConfigValue($name); 186 } 187 188 /** 189 * returns the data structure associated with this name 190 * 191 * @param string $name 37 * @param string $method name of the method to call 38 * @param array $arguments arguments to call 192 39 * @return mixed 193 40 * @throws stubXJConfException 194 41 */ 195 public function getConfigValue($name)42 public function __call($method, $arguments) 196 43 { 197 if (null == $this->xmlParser) { 198 throw new stubXJConfException('Invalid state: needs to parse first.'); 44 try { 45 return call_user_method_array($method, $this->realFacade, $arguments); 46 } catch (Exception $e) { 47 throw new stubXJConfException($e->getMessage, $e); 199 48 } 200 201 return $this->xmlParser->getConfigValue($name);202 }203 204 /**205 * returns a list of all data structures206 *207 * @return mixed208 * @throws stubXJConfException209 */210 public function getConfigValues()211 {212 if (null == $this->xmlParser) {213 throw new stubXJConfException('Invalid state: needs to parse first.');214 }215 216 return $this->xmlParser->getConfigValues();217 49 } 218 50 } trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfLoader.php
r312 r580 8 8 * @subpackage util_xjconf 9 9 */ 10 stubClassLoader::load('net.stubbles.util.xjconf.xjconf'); 11 XJConfLoader::load('XJConfClassLoader'); 10 stubClassLoader::load('net.xjconf.XJConfClassLoader'); 12 11 /** 13 12 * Class loader to use for XJConf. trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfProxy.php
r562 r580 1 1 <?php 2 2 /** 3 * Proxy for the XJConfFacade.3 * Proxy for XJConf. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 7 7 * @subpackage util_xjconf 8 8 */ 9 stubClassLoader::load('net.stubbles.util.stubFactory', 10 'net.stubbles.util.xjconf.xjconf' 11 ); 9 stubClassLoader::load('net.stubbles.util.stubFactory'); 12 10 /** 13 * Proxy for the XJConfFacade.11 * Proxy for XJConf. 14 12 * 15 13 * @package stubbles … … 73 71 } 74 72 75 $xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 76 $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/' . $this->initializer->getDescriptor() . '.xml')); 73 stubClassLoader::load('net.stubbles.util.xjconf.xjconfReal'); 74 $xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance()))); 75 $xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/' . $this->initializer->getDescriptor() . '.xml')); 77 76 $xjconf->enableXIncludes(); 78 77 foreach ($extensions as $extension) { trunk/src/main/php/net/stubbles/util/xjconf/xjconf.php
r538 r580 7 7 * @subpackage util_xjconf 8 8 */ 9 $xjConfUri = StarClassRegistry::getUriForClass('net.xjconf.XJConfLoader'); 10 if (null === $xjConfUri) { 11 /** 12 * Try to include XJConf from PEAR installation 13 */ 14 if (!@include 'XJConf/XJConfLoader.php') { 15 throw new stubException('XJConf could not be found in lib nor in include path.'); 16 } 17 } else { 18 /** 19 * Include XJConf via Star 20 */ 21 require $xjConfUri; 22 } 23 stubClassLoader::load('net.stubbles.util.xjconf.stubXJConfLoader', 9 stubClassLoader::load('net.stubbles.util.xjconf.stubXJConfException', 24 10 'net.stubbles.util.xjconf.stubXJConfFacade', 25 'net.stubbles.util.xjconf.stubXJConfException',26 11 'net.stubbles.util.xjconf.stubXJConfInitializer', 27 'net.stubbles.util.xjconf.stubXJConfProxy', 28 'net.stubbles.util.xjconf.stubConfigXJConfExtension' 12 'net.stubbles.util.xjconf.stubXJConfProxy' 29 13 ); 30 14 ?> trunk/src/main/php/net/stubbles/websites/processors/stubJsonRpcProcessor.php
r542 r580 14 14 'net.stubbles.service.annotations.stubWebMethodAnnotation', 15 15 'net.stubbles.service.stubStatefulService', 16 'net.stubbles.util.encoding.stubEncodingHelper'); 16 'net.stubbles.util.encoding.stubEncodingHelper', 17 'net.stubbles.util.xjconf.xjconf', 18 'net.stubbles.util.xjconf.xjconfReal' 19 ); 17 20 18 21 /** … … 69 72 public function doProcess() { 70 73 71 $xjconf = new stubXJConfFacade( array('__default' => stubXJConfLoader::getInstance()));72 $xjconf-> parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/json-rpc-service.xml'));74 $xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance()))); 75 $xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/json-rpc-service.xml')); 73 76 $configFile = stubConfig::getConfigPath() . '/xml/json-rpc-service.xml'; 74 77 $xjconf->parse($configFile); trunk/src/main/php/net/stubbles/websites/stubPageFactory.php
r557 r580 7 7 * @subpackage websites 8 8 */ 9 stubClassLoader::load('net.stubbles.util.stubFactory', 10 'net.stubbles.util.xjconf.stubXJConfLoader', 11 'net.stubbles.websites.stubPage', 9 stubClassLoader::load('net.stubbles.websites.stubPage', 12 10 'net.stubbles.websites.stubPageConfigurationException' 13 11 ); trunk/src/main/php/net/stubbles/websites/stubPageXJConfFactory.php
r447 r580 9 9 stubClassLoader::load('net.stubbles.util.stubFactory', 10 10 'net.stubbles.util.xjconf.xjconf', 11 'net.stubbles.util.xjconf.xjconfReal', 11 12 'net.stubbles.websites.stubPageConfigurationException', 12 13 'net.stubbles.websites.stubPageFactory' … … 33 34 { 34 35 if (null == self::$xjconf) { 35 self::$xjconf = new stubXJConfFacade( array('__default' => stubXJConfLoader::getInstance()));36 self::$xjconf-> parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/websites.xml'));36 self::$xjconf = new stubXJConfFacade(new XJConfFacade(array('__default' => stubXJConfLoader::getInstance()))); 37 self::$xjconf->addDefinitions(stubFactory::getResourceURIs('xjconf/websites.xml')); 37 38 } 38 39 } trunk/src/test/php/net/stubbles/util/xjconf/stubXJConfProxyTestCase.php
r538 r580 9 9 stubClassLoader::load('net.stubbles.util.xjconf.stubXJConfProxy'); 10 10 Mock::generate('stubXJConfInitializer'); 11 Mock::generate('stubXJConfFacade');12 11 /** 13 12 * Tests for net.stubbles.util.xjconf.stubXJConfProxy … … 93 92 * assure that values are taken from cache is cache file is newer than data file 94 93 */ 95 public function testIsCachedAndCacheIsNewer()96 {97 file_put_contents($this->cacheFile, serialize(array('foo' => 'bar')));98 touch($this->configFile, (time() - 100));99 touch($this->cacheFile, time());100 $this->xjConfInitializer->expectOnce('setCacheData', array(array('foo' => 'bar')));101 $this->xjConfInitializer->expectNever('getCacheData');102 $this->xjConfProxy->process();103 }104 105 /**94 public function testIsCachedAndCacheIsNewer() 95 { 96 file_put_contents($this->cacheFile, serialize(array('foo' => 'bar'))); 97 touch($this->configFile, (time() - 100)); 98 touch($this->cacheFile, time()); 99 $this->xjConfInitializer->expectOnce('setCacheData', array(array('foo' => 'bar'))); 100 $this->xjConfInitializer->expectNever('getCacheData'); 101 $this->xjConfProxy->process(); 102 } 103 104 /** 106 105 * assure that values are created and cached if the cache file is older than the data file 107 106 */ 108 public function testIsCachedAndCacheIsOlder()109 {110 file_put_contents($this->cacheFile, serialize(array('foo' => 'bar')));111 touch($this->configFile, (time()));112 touch($this->cacheFile, time() - 100);113 $this->xjConfInitializer->expectNever('setCacheData');114 $this->xjConfInitializer->expectOnce('loadData');115 $this->xjConfInitializer->expectOnce('getCacheData');116 $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bar'));117 $this->xjConfProxy->process();118 $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bar'));119 }120 121 /**107 public function testIsCachedAndCacheIsOlder() 108 { 109 file_put_contents($this->cacheFile, serialize(array('foo' => 'bar'))); 110 touch($this->configFile, (time())); 111 touch($this->cacheFile, time() - 100); 112 $this->xjConfInitializer->expectNever('setCacheData'); 113 $this->xjConfInitializer->expectOnce('loadData'); 114 $this->xjConfInitializer->expectOnce('getCacheData'); 115 $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bar')); 116 $this->xjConfProxy->process(); 117 $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bar')); 118 } 119 120 /** 122 121 * assure that values are created and cached if they were not cached before 123 122 */ 124 public function testIsNotCached()125 {126 $this->xjConfInitializer->expectNever('setCacheData');127 $this->xjConfInitializer->expectOnce('loadData');128 $this->xjConfInitializer->expectOnce('getCacheData');129 $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bum'));130 $this->xjConfProxy->process();131 $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bum'));132 }123 public function testIsNotCached() 124 { 125 $this->xjConfInitializer->expectNever('setCacheData'); 126 $this->xjConfInitializer->expectOnce('loadData'); 127 $this->xjConfInitializer->expectOnce('getCacheData'); 128 $this->xjConfInitializer->setReturnValue('getCacheData', array('baz' => 'bum')); 129 $this->xjConfProxy->process(); 130 $this->assertEqual(unserialize(file_get_contents($this->cacheFile)), array('baz' => 'bum')); 131 } 133 132 } 134 133 ?> trunk/src/test/php/net/stubbles/websites/stubFrontControllerProcessTestCase.php
r473 r580 15 15 Mock::generate('stubProcessor'); 16 16 Mock::generate('stubProcessorResolver'); 17 Mock::generate('stubXJConfFacade');18 17 Mock::generate('stubInterceptorInitializer'); 19 18 Mock::generate('stubProcessorResolverFactory');
