$value) { if (substr($key, 0, 1) == ':') { $result[substr($key, 1)] = $value; if ($remove) unset($request[$key]); } } return $result; } // Takes the hash "$request". The keys of its entries $key => $value are supposed // to have the following form // [functionname@]fieldname[:]) // If the fieldname is followed by the (optional) : this field is handled as // one of database key field names. // If the fieldname as preceded by functionname@, this function should be applied // to the corresponding value (but this is not done within this function). // // Return hashes: // $key_field_value_map: // Contains key => value pairs for database keys fields // The database key fields are freed from the : at the end and the optional // functionname@ at the beginning. // $field_value_map: The rest of the fields. // The fields are freed from the optional // functionname@ at the beginning. // $key_function_map: A hash with all keys that have functionnames // The functionnames are freed from the @ at the end // // Example: // $request = array('id:' => 7, 'name' => 'hugo', 'md5@password' => 'abc'); // // result: // $key_field_value_map == array('id' => 7) // $field_value_map == array('name' => 'hugo', 'password' => 'abc') // $key_function_map == array('password' => 'md5'); function decodeRequest($request, &$key_field_value_map, &$field_value_map, &$key_function_map) { // Begin with empty results $key_field_value_map = array(); $field_value_map = array(); $key_function_map = array(); foreach ($request as $key => $value) { // Split $key in $functionname $fieldname $isdbkey // - Init $functionname = NULL; $fieldname = ''; $isdbkey = FALSE; // - functionname $functionname_keyname = explode('@', $key); if (count($functionname_keyname) == 2) { $key = $functionname_keyname[1]; $functionname = $functionname_keyname[0]; } // - isdbkey if (substr($key, -1) == ':') { $key = substr($key, 0, -1); $isdbkey = TRUE; } // - fieldname $fieldname = $key; // Insert in the corresponding hashes if ($isdbkey) $key_field_value_map[$fieldname] = $value; else $field_value_map[$fieldname] = $value; if (!is_null($functionname)) $key_function_map[$fieldname] = $functionname; } } ?>