Skip to content

Commit

Permalink
Move constant_replace() to ConfigParser class as static method
Browse files Browse the repository at this point in the history
  • Loading branch information
dregad committed Apr 30, 2016
1 parent 9d78247 commit 3bb856e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 2 additions & 16 deletions adm_config_set.php
Expand Up @@ -107,10 +107,10 @@
$t_value = $f_value;
break;
case CONFIG_TYPE_INT:
$t_value = (integer)constant_replace( trim( $f_value ) );
$t_value = (integer)ConfigParser::constant_replace( $f_value );
break;
case CONFIG_TYPE_FLOAT:
$t_value = (float)constant_replace( trim( $f_value ) );
$t_value = (float)ConfigParser::constant_replace( $f_value );
break;
case CONFIG_TYPE_COMPLEX:
default:
Expand All @@ -131,17 +131,3 @@
form_security_purge( 'adm_config_set' );

print_successful_redirect( 'adm_config_report.php' );

/**
* Check if the passed string is a constant and returns its value
* if yes, or the string itself if not
* @param string $p_name String to check.
* @return mixed|string value of constant $p_name, or $p_name itself
*/
function constant_replace( $p_name ) {
if( is_string( $p_name ) && defined( $p_name ) ) {
# we have a constant
return constant( $p_name );
}
return $p_name;
}
18 changes: 16 additions & 2 deletions core/classes/ConfigParser.class.php
Expand Up @@ -80,6 +80,21 @@ public function parse() {
return $t_result;
}

/**
* Check if the passed string is a constant and returns its value if yes,
* or the string itself if not
* @param string $p_name String to check.
* @return mixed|string value of constant $p_name, or $p_name itself
*/
public static function constant_replace( $p_name ) {
$t_name = trim( $p_name );
if( is_string( $t_name ) && defined( $t_name ) ) {
# we have a constant
return constant( $t_name );
}
return $t_name;
}

/**
* Recursively process array declarations.
* @return array
Expand Down Expand Up @@ -144,7 +159,6 @@ protected function process_array() {
/**
* Process a scalar value.
* Handles string literals including defined constants
* @see constant_replace()
* @return mixed
* @throws Exception when there's an unexpected value
*/
Expand All @@ -165,7 +179,7 @@ protected function process_value() {
}

# Defined constants
$t_value = constant_replace( $t_value );
$t_value = $this->constant_replace( $t_value );
if( $t_value != $t_token[1] ) {
return $t_value;
}
Expand Down

0 comments on commit 3bb856e

Please sign in to comment.