summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Smith <chris@jalakai.co.uk>2015-05-17 13:02:07 +0200
committerChristopher Smith <chris@jalakai.co.uk>2015-05-17 13:02:07 +0200
commit4c353447a306680af86c38db3ef592e29a0cbe60 (patch)
tree4a6feef632ea9d025797c8186dbad3d06dc7902f
parent45ae4bb83834a513e709b960747f964dba90392b (diff)
downloadrpg-4c353447a306680af86c38db3ef592e29a0cbe60.tar.gz
rpg-4c353447a306680af86c38db3ef592e29a0cbe60.tar.bz2
Support negating of config values include earlier in the cascade
To negate a config value, prefix the value with an '!'. E.g. to disable recognition of the gopher scheme !gopher This applies to: - scheme - stopwords
-rw-r--r--inc/confutils.php37
1 files changed, 30 insertions, 7 deletions
diff --git a/inc/confutils.php b/inc/confutils.php
index 3e69b20be..7d7c043fa 100644
--- a/inc/confutils.php
+++ b/inc/confutils.php
@@ -120,7 +120,7 @@ function getInterwiki() {
function getWordblocks() {
static $wordblocks = null;
if ( !$wordblocks ) {
- $wordblocks = retrieveConfig('wordblock','file');
+ $wordblocks = retrieveConfig('wordblock','file',null,'array_merge_with_removal');
}
return $wordblocks;
}
@@ -133,11 +133,11 @@ function getWordblocks() {
function getSchemes() {
static $schemes = null;
if ( !$schemes ) {
- $schemes = retrieveConfig('scheme','file');
+ $schemes = retrieveConfig('scheme','file',null,'array_merge_with_removal');
+ $schemes = array_map('trim', $schemes);
+ $schemes = preg_replace('/^#.*/', '', $schemes);
+ $schemes = array_filter($schemes);
}
- $schemes = array_map('trim', $schemes);
- $schemes = preg_replace('/^#.*/', '', $schemes);
- $schemes = array_filter($schemes);
return $schemes;
}
@@ -202,7 +202,7 @@ function confToHash($file,$lower=false) {
* @param array $params optional additional params to pass to the callback
* @return array configuration values
*/
-function retrieveConfig($type,$fn,$params=null) {
+function retrieveConfig($type,$fn,$params=null,$combine='array_merge') {
global $config_cascade;
if(!is_array($params)) $params = array();
@@ -214,7 +214,7 @@ function retrieveConfig($type,$fn,$params=null) {
foreach ($config_cascade[$type][$config_group] as $file) {
if (file_exists($file)) {
$config = call_user_func_array($fn,array_merge(array($file),$params));
- $combined = array_merge($combined, $config);
+ $combined = $combine($combined, $config);
}
}
}
@@ -353,4 +353,27 @@ function conf_decodeString($str) {
return $str;
}
}
+
+/**
+ * array combination function to remove negated values (prefixed by !)
+ *
+ * @param array $current
+ * @param array $new
+ *
+ * @return array the combined array, numeric keys reset
+ */
+function array_merge_with_removal($current, $new) {
+ foreach ($new as $val) {
+ if (substr($val,0,1) == '!') {
+ $idx = array_search(substr($val,1),$current);
+ if ($idx !== false) {
+ unset($current[$idx]);
+ }
+ } else {
+ $current[] = $val;
+ }
+ }
+
+ return array_slice($current,0);
+}
//Setup VIM: ex: et ts=4 :