[evolvis-commits] r15283: Variable substitution in configuration variables (with unit tests)

mirabilos at evolvis.org mirabilos at evolvis.org
Mon Feb 28 23:53:13 CET 2011


Author: mirabilos
Date: 2011-02-28 23:53:13 +0100 (Mon, 28 Feb 2011)
New Revision: 15283

Modified:
   trunk/gforge_base/evolvisforge-5.1/gforge/common/include/config.php
   trunk/gforge_base/evolvisforge-5.1/gforge/plugins/scmsvn/etc/scmsvn.ini
   trunk/gforge_base/evolvisforge-5.1/tests/unit/config/ConfigTest.php
Log:
Variable substitution in configuration variables (with unit tests)

Modified: trunk/gforge_base/evolvisforge-5.1/gforge/common/include/config.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/common/include/config.php	2011-02-28 22:53:11 UTC (rev 15282)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/common/include/config.php	2011-02-28 22:53:13 UTC (rev 15283)
@@ -39,7 +39,18 @@
 		    || !isset ($this->settings[$section][$var])) {
 			return NULL ;
 		}
-		return $this->settings[$section][$var] ;
+
+		$tmp = $this->settings[$section][$var] ;
+		preg_match_all ('/\$[a-z_]+\/[a-z_]+/', $tmp, $matches) ;
+
+		foreach ($matches[0] as $m) {
+			$c = explode ('/', substr($m,1)) ;
+			
+			if (isset ($this->settings[$c[0]][$c[1]])) {
+				$tmp = str_replace ($m, $this->get_value($c[0],$c[1]), $tmp) ;
+			}
+		}
+		return $tmp ;
 	}
 
 	public function set_value ($section, $var, $value) {
@@ -179,8 +190,8 @@
 			while (false !== ($file = readdir($handle))) {
 				if ($file != "." 
 			    	&& $file != ".."
-			    	// Avoid .bak, .old, .dpkg-old and so on
-			    	&& preg_match ('/^[0-9a-zA-Z_-]+$/', $file)) {
+			    	// Avoid .bak, .old, .dpkg-old and so on, but keep .ini
+			    	&& preg_match ('/^[0-9a-zA-Z_-]+(.ini)?$/', $file)) {
 					$files[] = "$path/$file" ;
 				}
 			}

Modified: trunk/gforge_base/evolvisforge-5.1/gforge/plugins/scmsvn/etc/scmsvn.ini
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/plugins/scmsvn/etc/scmsvn.ini	2011-02-28 22:53:11 UTC (rev 15282)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/plugins/scmsvn/etc/scmsvn.ini	2011-02-28 22:53:13 UTC (rev 15283)
@@ -4,3 +4,5 @@
 use_ssh = no
 anonsvn_login = anonsvn
 anonsvn_password = anonsvn
+default_server = $core/web_host
+repos_path = $core/chroot/scmrepos/svn

Modified: trunk/gforge_base/evolvisforge-5.1/tests/unit/config/ConfigTest.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/tests/unit/config/ConfigTest.php	2011-02-28 22:53:11 UTC (rev 15282)
+++ trunk/gforge_base/evolvisforge-5.1/tests/unit/config/ConfigTest.php	2011-02-28 22:53:13 UTC (rev 15283)
@@ -41,6 +41,10 @@
 		$this->assertEquals('FusionForge', $forge_name);
 		$this->assertFalse($core__user_registration_restricted);
 
+		forge_read_config_dir (dirname(__FILE__) . '/../../../gforge/etc/config.ini.d') ;
+
+		$this->assertEquals('anonsvn', forge_get_config ('anonsvn_login', 'scmsvn'));
+		$this->assertEquals('/var/lib/gforge/chroot/scmrepos/svn', forge_get_config ('repos_path', 'scmsvn'));
 	}
 
 	/**



More information about the evolvis-commits mailing list