Changeset 538
- Timestamp:
- 04/15/07 13:03:27 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ipo/interceptors/stubInterceptorXJConfInitializer.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/ipo/interceptors/stubPostInterceptor.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/ipo/interceptors/stubPreInterceptor.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/rdbms/stubDatabaseConnectionData.php (modified) (14 diffs)
- trunk/src/main/php/net/stubbles/rdbms/stubDatabaseInitializer.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/util/stubRegistryXJConfInitializer.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfInitializer.php (added)
- trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfProxy.php (added)
- trunk/src/main/php/net/stubbles/util/xjconf/xjconf.php (modified) (1 diff)
- trunk/src/main/resources/xjconf/config.xml (moved) (moved from trunk/src/main/resources/xjconf/registry.xml)
- trunk/src/test/php/net/stubbles/integration/DatabaseTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/rdbms/RDBMSTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/rdbms/stubDatabaseInitializerTestCase.php (added)
- trunk/src/test/php/net/stubbles/util/UtilTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/stubRegistryXJConfInitializerTestCase.php (modified) (4 diffs)
- trunk/src/test/php/net/stubbles/util/xjconf (added)
- trunk/src/test/php/net/stubbles/util/xjconf/stubXJConfProxyTestCase.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/interceptors/stubInterceptorXJConfInitializer.php
r443 r538 8 8 */ 9 9 stubClassLoader::load('net.stubbles.ipo.interceptors.stubInterceptorInitializer', 10 'net.stubbles.util.stubFactory',11 10 'net.stubbles.util.xjconf.xjconf' 12 11 ); … … 16 15 * @package stubbles 17 16 * @subpackage ipo_interceptors 17 * @todo write unit test 18 18 */ 19 class stubInterceptorXJConfInitializer extends stubBaseObject implements stubInterceptorInitializer 19 class stubInterceptorXJConfInitializer extends stubBaseObject implements stubInterceptorInitializer, stubXJConfInitializer 20 20 { 21 /**22 * name of the config file to use for initializing23 *24 * @var string25 */26 protected $configFile;27 21 /** 28 22 * list of pre interceptors … … 37 31 */ 38 32 protected $postInterceptors = array(); 39 33 40 34 /** 41 * constructor 35 * returns the descriptor that identifies this initializer 36 * 37 * @return string 42 38 */ 43 public function __construct()39 public function getDescriptor() 44 40 { 45 $this->configFile = stubConfig::getConfigPath() . '/xml/interceptors.xml';41 return 'interceptors'; 46 42 } 47 43 48 44 /** 49 * sets the name of the config gile to use45 * returns the data to cache 50 46 * 51 * @ param string $configFile47 * @return array 52 48 */ 53 public function setConfigFile($configFile)49 public function getCacheData() 54 50 { 55 $this->configFile = $configFile; 51 $cacheData = array('preInterceptors' => array(), 'postInterceptors' => array()); 52 foreach ($this->preInterceptors as $preInterceptor) { 53 if ($preInterceptor instanceof stubSerializable) { 54 $cacheData['preInterceptors'][] = $preInterceptor->getSerialized(); 55 } else { 56 $cacheData['preInterceptors'][] = $preInterceptor->getClassName(); 57 } 58 } 59 60 foreach ($this->postInterceptors as $postInterceptor) { 61 if ($postInterceptor instanceof stubSerializable) { 62 $cacheData['postInterceptors'][] = $postInterceptor->getSerialized(); 63 } else { 64 $cacheData['postInterceptors'][] = $postInterceptor->getClassName(); 65 } 66 } 67 68 return $cacheData; 56 69 } 57 70 71 /** 72 * sets the data from the cache 73 * 74 * @param array $cacheData 75 */ 76 public function setCacheData(array $cacheData) 77 { 78 foreach ($cacheData['preInterceptors'] as $preInterceptor) { 79 if ($preInterceptor instanceof stubSerializable) { 80 $this->preInterceptors[] = $preInterceptor->getUnserialized(); 81 } else { 82 stubClassLoader::load($preInterceptor); 83 $nqClassName = stubClassLoader::getNonQualifiedClassName($preInterceptor); 84 if (class_exists($nqClassName, false) == false) { 85 stubClassLoader::load($preInterceptor); 86 } 87 88 $this->preInterceptors[] = new $nqClassName(); 89 } 90 } 91 92 foreach ($cacheData['postInterceptors'] as $postInterceptor) { 93 if ($postInterceptor instanceof stubSerializable) { 94 $this->postInterceptors[] = $postInterceptor->getUnserialized(); 95 } else { 96 $nqClassName = stubClassLoader::getNonQualifiedClassName($postInterceptor); 97 if (class_exists($nqClassName, false) == false) { 98 stubClassLoader::load($postInterceptor); 99 } 100 101 $this->postInterceptors[] = new $nqClassName(); 102 } 103 } 104 } 105 106 /** 107 * will be called in case the stubXJConfProxy did not found the data in the 108 * cache and the initializer has to load values from the facade 109 * 110 * @param stubXJConfFacade $xjconf 111 */ 112 public function loadData(stubXJConfFacade $xjconf) 113 { 114 $this->preInterceptors = $xjconf->getConfigValue('preInterceptors'); 115 $this->postInterceptors = $xjconf->getConfigValue('postInterceptors'); 116 } 117 58 118 /** 59 119 * initialize the interceptors … … 63 123 public function init() 64 124 { 65 $xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 66 $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/interceptors.xml')); 67 $xjconf->enableXIncludes(); 68 $xjconf->parse($this->configFile); 69 $this->preInterceptors = $xjconf->getConfigValue('preInterceptors'); 70 $this->postInterceptors = $xjconf->getConfigValue('postInterceptors'); 125 $xjconfProxy = new stubXJConfProxy($this); 126 $xjconfProxy->process(); 71 127 } 72 128 129 /** 130 * sets the list of pre interceptors 131 * 132 * @param array<stubPreInterceptor> $preInterceptors 133 */ 134 public function setPreInterceptors(array $preInterceptors) 135 { 136 $this->preInterceptors = $preInterceptors; 137 } 138 73 139 /** 74 140 * returns the list of pre interceptors … … 80 146 return $this->preInterceptors; 81 147 } 82 148 149 /** 150 * sets the list of pre interceptors 151 * 152 * @param array<stubPostInterceptor> $postInterceptors 153 */ 154 public function setPostInterceptors(array $postInterceptors) 155 { 156 $this->postInterceptors = $postInterceptors; 157 } 158 83 159 /** 84 160 * returns the list of post interceptors trunk/src/main/php/net/stubbles/ipo/interceptors/stubPostInterceptor.php
r473 r538 16 16 * @subpackage ipo_interceptors 17 17 */ 18 interface stubPostInterceptor 18 interface stubPostInterceptor extends stubObject 19 19 { 20 20 /** trunk/src/main/php/net/stubbles/ipo/interceptors/stubPreInterceptor.php
r473 r538 16 16 * @subpackage ipo_interceptors 17 17 */ 18 interface stubPreInterceptor 18 interface stubPreInterceptor extends stubObject 19 19 { 20 20 /** trunk/src/main/php/net/stubbles/rdbms/stubDatabaseConnectionData.php
r400 r538 13 13 * @subpackage rdbms 14 14 */ 15 class stubDatabaseConnectionData extends stub BaseObject15 class stubDatabaseConnectionData extends stubSerializableObject 16 16 { 17 17 /** … … 56 56 */ 57 57 protected $driverOptions = array(); 58 58 59 59 /** 60 60 * set the id to use for the connection … … 70 70 $this->id = $id; 71 71 } 72 72 73 73 /** 74 74 * return the id to use for the connection … … 80 80 return $this->id; 81 81 } 82 82 83 83 /** 84 84 * checks whether a value is equal to the class … … 99 99 return false; 100 100 } 101 101 102 102 /** 103 103 * sets the full qualified name of the class to use for the connection … … 109 109 $this->fqClassName = $fqClassName; 110 110 } 111 111 112 112 /** 113 113 * returns the full qualified name of the class to use for the connection … … 119 119 return $this->fqClassName; 120 120 } 121 121 122 122 /** 123 123 * sets the Data Source Name … … 129 129 $this->dsn = $dsn; 130 130 } 131 131 132 132 /** 133 133 * returns the Data Source Name … … 139 139 return $this->dsn; 140 140 } 141 141 142 142 /** 143 143 * sets the user name … … 149 149 $this->userName = $userName; 150 150 } 151 151 152 152 /** 153 153 * returns the user name … … 159 159 return $this->userName; 160 160 } 161 161 162 162 /** 163 163 * sets the password … … 169 169 $this->password = $password; 170 170 } 171 171 172 172 /** 173 173 * returns the user password … … 179 179 return $this->password; 180 180 } 181 181 182 182 /** 183 183 * sets a key=>value array of driver-specific connection options … … 189 189 $this->driverOptions = $driverOptions; 190 190 } 191 191 192 192 /** 193 193 * returns a key=>value array of driver-specific connection options trunk/src/main/php/net/stubbles/rdbms/stubDatabaseInitializer.php
r473 r538 8 8 */ 9 9 stubClassLoader::load('net.stubbles.ipo.interceptors.stubPreInterceptor', 10 'net.stubbles. util.stubFactory',10 'net.stubbles.rdbms.stubDatabaseConnectionPool', 11 11 'net.stubbles.util.xjconf.xjconf' 12 12 ); … … 17 17 * @subpackage rdbms 18 18 */ 19 class stubDatabaseInitializer extends stubBaseObject implements stubPreInterceptor 19 class stubDatabaseInitializer extends stubBaseObject implements stubPreInterceptor, stubXJConfInitializer 20 20 { 21 /** 22 * returns the descriptor that identifies this initializer 23 * 24 * @return string 25 */ 26 public function getDescriptor() 27 { 28 return 'rdbms'; 29 } 30 31 /** 32 * returns the data to cache 33 * 34 * @return array 35 */ 36 public function getCacheData() 37 { 38 $cacheData = array(); 39 foreach (stubDatabaseConnectionPool::getConnectionDataIds() as $connectionDataId) { 40 $cacheData[$connectionDataId] = stubDatabaseConnectionPool::getConnectionData($connectionDataId)->getSerialized(); 41 } 42 43 return $cacheData; 44 } 45 46 /** 47 * sets the data from the cache 48 * 49 * @param array $cacheData 50 */ 51 public function setCacheData(array $cacheData) 52 { 53 foreach ($cacheData as $serialized) { 54 stubDatabaseConnectionPool::addConnectionData($serialized->getUnserialized()); 55 } 56 } 57 58 /** 59 * will be called in case the stubXJConfProxy did not found the data in the 60 * cache and the initializer has to load values from the facade 61 * 62 * @param stubXJConfFacade $xjconf 63 */ 64 public function loadData(stubXJConfFacade $xjconf) 65 { 66 // intentionally empty 67 } 68 21 69 /** 22 70 * initialize the Registry with configuration values from given configuration file 23 71 * 24 * @param string $configFile25 72 * @throws stubXJConfException 26 73 */ 27 public static function init($configFile)74 public function init() 28 75 { 29 $xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 30 $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/rdbms.xml')); 31 $xjconf->enableXIncludes(); 32 $xjconf->parse($configFile); 76 $xjconfProxy = new stubXJConfProxy($this); 77 $xjconfProxy->process(); 33 78 } 34 79 35 80 /** 36 81 * does the preprocessing stuff 37 82 * 38 * @param stubRequest $request access to request data 39 * @param stubSession $session access to session data 40 * @param stubResponse $response access to response data 83 * @param stubRequest $request access to request data 84 * @param stubSession $session access to session data 85 * @param stubResponse $response access to response data 86 * @throws stubXJConfException 41 87 */ 42 88 public function preProcess(stubRequest $request, stubSession $session, stubResponse $response) 43 89 { 44 self::init(stubConfig::getConfigPath() . '/xml/rdbms.xml');90 $this->init(); 45 91 } 46 92 } trunk/src/main/php/net/stubbles/util/stubRegistryXJConfInitializer.php
r528 r538 1 1 <?php 2 2 /** 3 * Class for initializing the Registry.3 * Class for initializing the stubRegistry via XJConf. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 7 7 * @subpackage util 8 8 */ 9 stubClassLoader::load('net.stubbles.util.stubFactory', 10 'net.stubbles.util.stubRegistry', 9 stubClassLoader::load('net.stubbles.util.stubRegistry', 11 10 'net.stubbles.util.stubRegistryInitializer', 12 11 'net.stubbles.util.xjconf.xjconf' 13 12 ); 14 13 /** 15 * Class for initializing the Registry.14 * Class for initializing the stubRegistry via XJConf. 16 15 * 17 16 * @package stubbles 18 17 * @subpackage util 19 18 */ 20 class stubRegistryXJConfInitializer extends stubBaseObject implements stubRegistryInitializer 19 class stubRegistryXJConfInitializer extends stubBaseObject implements stubRegistryInitializer, stubXJConfInitializer 21 20 { 22 21 /** 23 * name of the config file to use for initializing22 * returns the descriptor that identifies this initializer 24 23 * 25 * @ varstring24 * @return string 26 25 */ 27 protected $configFile; 28 /** 29 * name of the cache file to use 30 * 31 * @var string 32 */ 33 protected $cacheFile; 34 35 /** 36 * constructor 37 */ 38 public function __construct() 26 public function getDescriptor() 39 27 { 40 $this->configFile = stubConfig::getConfigPath() . '/xml/config.xml'; 41 $this->cacheFile = stubConfig::getCachePath() . '/config.cache'; 28 return 'config'; 42 29 } 43 30 44 31 /** 45 * sets the name of the config file to use32 * returns the data to cache 46 33 * 47 * @ param string $configFile34 * @return array 48 35 */ 49 public function setConfigFile($configFile)36 public function getCacheData() 50 37 { 51 $this->configFile = $configFile; 38 $cacheData = array(); 39 foreach (stubRegistry::getConfigKeys() as $key) { 40 $cacheData[$key] = stubRegistry::getConfig($key); 41 } 42 43 return $cacheData; 44 } 45 46 /** 47 * sets the data from the cache 48 * 49 * @param array $cacheData 50 */ 51 public function setCacheData(array $cacheData) 52 { 53 foreach ($cacheData as $key => $value) { 54 stubRegistry::setConfig($key, $value); 55 } 56 } 57 58 /** 59 * will be called in case the stubXJConfProxy did not found the data in the 60 * cache and the initializer has to load values from the facade 61 * 62 * @param stubXJConfFacade $xjconf 63 */ 64 public function loadData(stubXJConfFacade $xjconf) 65 { 66 // intentionally empty 52 67 } 53 68 … … 55 70 * initialize the Registry with configuration values from given configuration file 56 71 * 57 * @param string $configFile58 72 * @throws stubXJConfException 59 73 */ 60 74 public function init() 61 75 { 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(); 71 $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/registry.xml')); 72 $xjconf->enableXIncludes(); 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())); 76 $xjconfProxy = new stubXJConfProxy($this); 77 $xjconfProxy->process(); 120 78 } 121 79 } trunk/src/main/php/net/stubbles/util/xjconf/xjconf.php
r535 r538 24 24 'net.stubbles.util.xjconf.stubXJConfFacade', 25 25 'net.stubbles.util.xjconf.stubXJConfException', 26 'net.stubbles.util.xjconf.stubXJConfInitializer', 27 'net.stubbles.util.xjconf.stubXJConfProxy', 26 28 'net.stubbles.util.xjconf.stubConfigXJConfExtension' 27 29 ); trunk/src/test/php/net/stubbles/integration/DatabaseTestCase.php
r400 r538 21 21 public function testDatabaseInitializer() 22 22 { 23 stubDatabaseInitializer::init(stubConfig::getConfigPath() . '/xml/rdbms.xml'); 23 $dbInitializer = new stubDatabaseInitializer(); 24 $dbInitializer->init(); 24 25 $this->assertTrue(stubDatabaseConnectionPool::hasConnectionData()); 25 26 $connectionData = stubDatabaseConnectionPool::getConnectionData(); trunk/src/test/php/net/stubbles/rdbms/RDBMSTestSuite.php
r482 r538 24 24 $this->addTestFile($dir . '/stubDatabaseConnectionDataTestCase.php'); 25 25 $this->addTestFile($dir . '/stubDatabaseConnectionPoolTestCase.php'); 26 $this->addTestFile($dir . '/stubDatabaseInitializerTestCase.php'); 26 27 27 28 // criteria trunk/src/test/php/net/stubbles/util/UtilTestSuite.php
r531 r538 53 53 $this->addTestFile($dir . '/validators/stubRegexValidatorTestCase.php'); 54 54 $this->addTestFile($dir . '/validators/stubXorValidatorTestCase.php'); 55 56 // xjconf 57 $this->addTestFile($dir . '/xjconf/stubXJConfProxyTestCase.php'); 55 58 } 56 59 } trunk/src/test/php/net/stubbles/util/stubRegistryXJConfInitializerTestCase.php
r526 r538 3 3 * Tests for net.stubbles.util.stubRegistryXJConfInitializer 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_test 8 8 */ 9 stubClassLoader::load('net.stubbles.util.stubRegistry', 10 'net.stubbles.util.stubRegistryXJConfInitializer' 11 ); 12 Mock::generate('stubXJConfFacade'); 13 Mock::generatePartial('stubRegistryXJConfInitializer', 14 'MockstubRegistryXJConfInitializer', 15 array('isCacheUpToDate', 16 'getCacheData', 17 'setCacheData', 18 'createXJConfFacade' 19 ) 20 ); 9 stubClassLoader::load('net.stubbles.util.stubRegistryXJConfInitializer'); 21 10 /** 22 11 * Tests for net.stubbles.util.stubRegistryXJConfInitializer … … 30 19 * instance to test 31 20 * 32 * @var MockstubRegistryXJConfInitializer21 * @var stubRegistryXJConfInitializer 33 22 */ 34 23 protected $registryXJConfInitializer; … … 39 28 public function setUp() 40 29 { 41 $this->registryXJConfInitializer = new MockstubRegistryXJConfInitializer(); 42 $this->registryXJConfInitializer->setReturnValue('createXJConfFacade', new MockstubXJConfFacade()); 30 $this->registryXJConfInitializer = new stubRegistryXJConfInitializer(); 43 31 } 44 32 … … 54 42 55 43 /** 56 * assure that values are cached if they were not cached before44 * test that the descriptor is correct 57 45 */ 58 public function testNonCached() 46 public function testDescriptor() 47 { 48 $this->assertEqual($this->registryXJConfInitializer->getDescriptor(), 'config'); 49 } 50 51 /** 52 * assure that values are returned correct 53 */ 54 public function testGetCacheData() 59 55 { 60 56 stubRegistry::setConfig('foo', 'bar'); 61 57 stubRegistry::setConfig('baz', 313); 62 $this->registryXJConfInitializer->setReturnValue('isCacheUpToDate', false); 63 $this->registryXJConfInitializer->expect('setCacheData', array(array('foo' => 'bar', 'baz' => 313))); 64 $this->registryXJConfInitializer->init(); 58 $this->assertEqual($this->registryXJConfInitializer->getCacheData(), array('foo' => 'bar', 'baz' => 313)); 65 59 } 66 60 67 61 /** 68 * assure that values are read from cache62 * assure that values are set correct 69 63 */ 70 public function test Cached()64 public function testSetCacheData() 71 65 { 72 $this->registryXJConfInitializer->setReturnValue('isCacheUpToDate', true); 73 $this->registryXJConfInitializer->setReturnValue('getCacheData', array('foo' => 'bar', 'baz' => 313)); 74 $this->registryXJConfInitializer->expectNever('setCacheData'); 75 $this->registryXJConfInitializer->init(); 76 66 $this->registryXJConfInitializer->setCacheData(array('foo' => 'bar', 'baz' => 313)); 77 67 $this->assertEqual(stubRegistry::getConfigKeys(), array('foo', 'baz')); 78 68 $this->assertEqual(stubRegistry::getConfig('foo'), 'bar');
