<?php

Class SimpleModuleModelBuilder {

	public static function generateNondestructiveUrl($new_params = array(), $remove_params = array()) {

		$url = "";

		$parsed_url = parse_url( $_SERVER['REQUEST_URI'] );
		$parsed_query = array();
		if ( isset( $parsed_url['query'] )  && !empty( $parsed_url['query'] ) ) {
			parse_str( $parsed_url['query'], $parsed_query);
		}

		foreach ($remove_params as $key => $value) {
			// check if all need to be removed
			if ( $value == "*" ) {
				$parsed_query = array();
				break;
			}
			unset($parsed_query[$value]);
		}

		$merged_query = array_merge($parsed_query, $new_params);

		$url = $parsed_url['path'];
		if ( !empty($merged_query) ) {
			$url .= "?".http_build_query($merged_query);
		}

		return $url;
	}

}