Skip to content

Commit 7bcf5e1

Browse files
committed
Add utility function to get values from config file
Signed-off-by: Riddhesh Sanghvi <[email protected]>
1 parent dee3071 commit 7bcf5e1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

php/utils.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,3 +1623,19 @@ function get_curl_info( $url, $port = 80, $port_info = false, $auth = false ) {
16231623

16241624
return curl_getinfo( $ch, CURLINFO_HTTP_CODE );
16251625
}
1626+
1627+
/**
1628+
* Function to get config value for a given key.
1629+
*
1630+
* @param string $key Key to search in config file.
1631+
* @param string|null $default Default value of the given key.
1632+
*
1633+
* @return string|null value of the asked key.
1634+
*/
1635+
function get_config_value( $key, $default = null ) {
1636+
1637+
$config_file_path = getenv( 'EE_CONFIG_PATH' ) ? getenv( 'EE_CONFIG_PATH' ) : EE_ROOT_DIR . '/config/config.yml';
1638+
$existing_config = Spyc::YAMLLoad( $config_file_path );
1639+
1640+
return empty( $existing_config[ $key ] ) ? $default : $existing_config[ $key ];
1641+
}

0 commit comments

Comments
 (0)