Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #15870: Deserialization issues caused by mc_config_get_string().

  • Loading branch information...
commit 75d39c5852fe05713ea436bed06f979a06eff02e 1 parent 8c4e3df
@vboctor authored
Showing with 42 additions and 1 deletion.
  1. +42 −1 api/soap/mc_config_api.php
View
43 api/soap/mc_config_api.php
@@ -24,6 +24,47 @@ function mc_config_get_string( $p_username, $p_password, $p_config_var ) {
return SoapObjectsFactory::newSoapFault( 'Client', "Config '$p_config_var' is undefined" );
}
- return config_get( $p_config_var );
+ $t_value = config_get( $p_config_var );
+
+ # If array, serialize to string to avoid php error relating to serializing array as string.
+ if ( is_array( $t_value ) ) {
+ $t_value = mci_serialize_array( $t_value );
+ }
+
+ return $t_value;
+}
+
+/**
+ * Serialize a standard or associative array to a string.
+ * Elements are going to be separated by a new line.
+ * Key and value are going to eb separated by a tab.
+ * Nested arrays are not supported. Type of keys/values doesn't affect the output.
+ * @param $p_array The array to serialize.
+ */
+function mci_serialize_array( $p_array ) {
+ $t_associative = array_keys( $p_array ) !== range( 0, count( $p_array ) - 1 );
+ $t_result = '';
+ $t_key_value_separator = "\t";
+ $t_value_separator = "\n";
+
+ if ( $t_associative ) {
+ foreach ( $p_array as $t_key => $t_value ) {
+ if ( !empty( $t_result ) ) {
+ $t_result .= $t_value_separator;
+ }
+
+ $t_result .= $t_key . $t_key_value_separator . $t_value;
+ }
+ } else {
+ foreach ( $p_array as $t_value ) {
+ if ( !empty( $t_result ) ) {
+ $t_result .= $t_value_separator;
+ }
+
+ $t_result .= $t_value;
+ }
+ }
+
+ return $t_result;
}
Please sign in to comment.
Something went wrong with that request. Please try again.