/** * Sets a config value * */ public function set_config($key, $val) { if (!is_null(self::$content)) { $pattern = '%(?sx) ( \\$' . "config\r\n\t\t\t\t\t\\[(['\"])\r\n\t\t\t\t\t(" . $key . ")\r\n\t\t\t\t\t\\2\\]\r\n\t\t\t\t\t\\s*=\\s*\r\n\t\t\t\t)\r\n\t\t\t\t(.+?);\r\n\t\t\t%"; $type = gettype($val); if ($type == 'string') { if (strtolower($val) == 'true') { $val = var_export(TRUE, TRUE); } else { if (strtolower($val) == 'false') { $val = var_export(FALSE, TRUE); } else { $val = "'" . $val . "'"; } } } if ($type == 'boolean') { $val = $val ? var_export(TRUE, TRUE) : var_export(FALSE, TRUE); } if ($type == 'array') { $val = preg_replace("/[0-9]+ \\=\\>/i", '', var_export($val, TRUE)); $val = str_replace("\n", "\r\n", $val); } self::$content = preg_replace($pattern, "\\1{$val};", self::$content); return TRUE; } return FALSE; }
/** * Sets a config value * * @param $key * @param $val * @param null $module_key * * @return bool */ public function set_config($key, $val, $module_key = NULL) { if (!is_null(self::$content)) { if (is_null($module_key)) { $pattern = '%(?sx) ( \\$' . "config\r\n\t\t\t\t\t\t\\[(['\"])\r\n\t\t\t\t\t\t(" . $key . ")\r\n\t\t\t\t\t\t\\2\\]\r\n\t\t\t\t\t\t\\s*=\\s*\r\n\t\t\t\t\t)\r\n\t\t\t\t\t(.+?);\r\n\t\t\t\t%"; } else { $pattern = "%([\"'](" . $key . ")[\"'][\\s]*?=>[\\s]*?)((?:(true|false),)|([\"'](.*?)[\"']))%"; // $pattern = "%([\"'](".$key.")[\"'][\s]*?=>[\s]*?)(.*?,)%"; } $type = gettype($val); if ($type == 'string') { if (strtolower($val) == 'true') { $val = var_export(TRUE, TRUE); } else { if (strtolower($val) == 'false') { $val = var_export(FALSE, TRUE); } else { $val = "'" . $val . "'"; } } if ((strtolower($val) == 'true' or strtolower($val) == 'false') && !is_null($module_key)) { $val .= ','; } } if ($type == 'boolean') { $val = $val ? var_export(TRUE, TRUE) : var_export(FALSE, TRUE); if (!is_null($module_key)) { $val .= ','; } } if ($type == 'array') { $val = preg_replace("/[0-9]+ \\=\\>/i", '', var_export($val, TRUE)); $val = str_replace("\n", "\r\n", $val); } /* Debug log_message('error', print_r($pattern, true)); preg_match($pattern, self::$content, $matches); log_message('error', print_r($matches, true)); */ if (is_null($module_key)) { self::$content = preg_replace($pattern, "\\1{$val};", self::$content); } else { self::$content = preg_replace($pattern, "\\1{$val}", self::$content); } return TRUE; } return FALSE; }