From fa0421d264fe743820121124899cc79401219d7f Mon Sep 17 00:00:00 2001 From: rajkp Date: Tue, 18 Jun 2024 16:45:28 +0530 Subject: [PATCH 1/3] Replace boolean value of config variables to literal string --- src/Config_Command.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Config_Command.php b/src/Config_Command.php index 35e39116..6a00d590 100644 --- a/src/Config_Command.php +++ b/src/Config_Command.php @@ -534,7 +534,7 @@ public function get( $args, $assoc_args ) { public function is_true( $args, $assoc_args ) { $value = $this->get_value( $assoc_args, $args ); - if ( boolval( $value ) ) { + if ( boolval( $value ) && 'false' !== $value ) { // Second condition is needed because we have literal "false" as string and boolval('false') is true. WP_CLI::halt( 0 ); } WP_CLI::halt( 1 ); @@ -578,7 +578,14 @@ private static function get_wp_config_vars( $wp_config_path = '' ) { ]; } - return array_merge( $wp_config_vars, $wp_config_constants, $wp_config_includes_array ); + $merged_vars = array_merge( $wp_config_vars, $wp_config_constants, $wp_config_includes_array ); + // Modify boolean values for easier handling. + foreach ( $merged_vars as $index => $var ) { + if ( 'boolean' === gettype( $var['value'] ) ) { + $merged_vars[ $index ]['value'] = $var['value'] ? 'true' : 'false'; + } + } + return $merged_vars; } /** From 1a3f3226bb2f106385a5ecd83bbe046248598991 Mon Sep 17 00:00:00 2001 From: rajkp Date: Wed, 19 Jun 2024 15:06:30 +0530 Subject: [PATCH 2/3] Show the boolean values only when displaying it to the user --- src/Config_Command.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Config_Command.php b/src/Config_Command.php index 6a00d590..8b1bb6c6 100644 --- a/src/Config_Command.php +++ b/src/Config_Command.php @@ -446,6 +446,14 @@ public function list_( $args, $assoc_args ) { if ( 'dotenv' === $assoc_args['format'] ) { return array_walk( $values, array( $this, 'print_dotenv' ) ); } + + if ( ! $strict ) { + foreach ( $values as $index => $value ) { + if ( is_bool( $value['value'] ) ) { + $values[ $index ]['value'] = $value['value'] ? 'true' : 'false'; + } + } + } Utils\format_items( $assoc_args['format'], $values, $assoc_args['fields'] ); } @@ -494,6 +502,10 @@ public function list_( $args, $assoc_args ) { */ public function get( $args, $assoc_args ) { $value = $this->get_value( $assoc_args, $args ); + if ( is_bool( $value ) ) { + $value = $value ? 'true' : 'false'; + } + WP_CLI::print_value( $value, $assoc_args ); } @@ -534,7 +546,7 @@ public function get( $args, $assoc_args ) { public function is_true( $args, $assoc_args ) { $value = $this->get_value( $assoc_args, $args ); - if ( boolval( $value ) && 'false' !== $value ) { // Second condition is needed because we have literal "false" as string and boolval('false') is true. + if ( boolval( $value ) ) { WP_CLI::halt( 0 ); } WP_CLI::halt( 1 ); @@ -578,14 +590,7 @@ private static function get_wp_config_vars( $wp_config_path = '' ) { ]; } - $merged_vars = array_merge( $wp_config_vars, $wp_config_constants, $wp_config_includes_array ); - // Modify boolean values for easier handling. - foreach ( $merged_vars as $index => $var ) { - if ( 'boolean' === gettype( $var['value'] ) ) { - $merged_vars[ $index ]['value'] = $var['value'] ? 'true' : 'false'; - } - } - return $merged_vars; + return array_merge( $wp_config_vars, $wp_config_constants, $wp_config_includes_array ); } /** From 9f76add936cf5b2e7627c470e812a262499f9897 Mon Sep 17 00:00:00 2001 From: rajkp Date: Wed, 19 Jun 2024 15:12:14 +0530 Subject: [PATCH 3/3] Remove extra whitespace at end of line --- src/Config_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config_Command.php b/src/Config_Command.php index 8b1bb6c6..592d4d44 100644 --- a/src/Config_Command.php +++ b/src/Config_Command.php @@ -446,7 +446,7 @@ public function list_( $args, $assoc_args ) { if ( 'dotenv' === $assoc_args['format'] ) { return array_walk( $values, array( $this, 'print_dotenv' ) ); } - + if ( ! $strict ) { foreach ( $values as $index => $value ) { if ( is_bool( $value['value'] ) ) {