Skip to content

Commit 81c3c4e

Browse files
committed
Merge branch 'sagarnasit-fix/add-default-ssl-value' into develop
2 parents a8b9dac + 9572c8f commit 81c3c4e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

php/utils.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,3 +1732,32 @@ function random_name_generator() {
17321732

17331733
return $left[ array_rand( $left ) ] . '-' . $right[ array_rand( $right ) ];
17341734
}
1735+
1736+
/**
1737+
* @param array $assoc_args Arguments array.
1738+
* @param string $flag Flag to get the value.
1739+
* @param array $supported_flag_values array of supported flag values.
1740+
* @param string $default_value default flag value if flag is passed without value.
1741+
*
1742+
* @return string
1743+
* @throws EE\ExitException
1744+
*/
1745+
function get_value_if_flag_isset( $assoc_args, $flag, $supported_flag_values = [], $default_value = '' ) {
1746+
1747+
$flag_value = get_flag_value( $assoc_args, $flag );
1748+
$value = '';
1749+
1750+
if ( isset( $flag_value ) ) {
1751+
/**
1752+
* Set default flag value if flag is passed without value.
1753+
*/
1754+
$value = ( empty( $flag_value ) || true === $flag_value ) ? $default_value : $flag_value;
1755+
1756+
if ( empty( $value ) ) {
1757+
return $value;
1758+
} elseif ( ! in_array( $value, $supported_flag_values, true ) ) {
1759+
EE::error( sprintf( 'Invalid flag value passed %s', $value ) );
1760+
}
1761+
}
1762+
return $value;
1763+
}

0 commit comments

Comments
 (0)