<commit_before><?php

	/**
	 * glue
	 *
	 * Provides an easy way to map URLs to classes. URLs can be literal
	 * strings or regular expressions.
	 *
	 * When the URLs are processed:
	 *	  * deliminators (/) are automatically escaped: (\/)
	 *	  * The beginning and end are anchored (^ $)
	 *	  * An optional end slash is added (/?)
	 *		* The i option is added for case-insensitive searches
	 *
	 * Example:
	 *
	 * $urls = array(
	 *	 '/' => 'index',
	 *	 '/page/(\d+) => 'page'
	 * );
	 *
	 * class page {
	 *	  function GET($matches) {
	 *		  echo "Your requested page " . $matches[1];
	 *	  }
	 * }
	 *
	 * glue::stick($urls);
	 *
	 */
	class glue {

		/**
		 * stick
		 *
		 * the main static function of the glue class.
		 *
		 * @param   array		$urls  		The regex-based url to class mapping
		 * @param   string		$base  		Base url if not at root 
		 * @throws  Exception			   Thrown if corresponding class is not found
		 * @throws  Exception			   Thrown if no match is found
		 * @throws  BadMethodCallException  Thrown if a corresponding GET,POST is not found
		 *
		 */
		static function stick ($urls, $base = NULL) {
			$method = strtoupper($_SERVER['REQUEST_METHOD']);
			$path = $_SERVER['REQUEST_URI'];

			if($base != NULL) {
				$path = substr($path, strpos($path, $base)+strlen($base));
			}

			$found = false;

			krsort($urls);

			foreach ($urls as $regex => $class) {
				$regex = str_replace('/', '\/', $regex);
				$regex = '^' . $regex . '\/?$';
				if (preg_match("/$regex/i", $path, $matches)) {
					$found = true;
					if (class_exists($class)) {
						$obj = new $class;
						if (method_exists($obj, $method)) {
							$obj->$method($matches);
						} else {
							throw new GlueMethodException("Could not find specified method in the class", $path, $class, $method);
						}
					} else {
						throw new GlueInternalException("Could not find specified class", $path, $class, $method);
					}
					break;
				}
			}
			if (!$found) {
				throw new GlueURLException("The URL accessed does not match any URL in the glue", $path);
			}
		}
	}
<commit_msg>Allow random GET parameters in URLs - the glue will now no longer try and parse them as part of the regex.<commit_after><?php

	/**
	 * glue
	 *
	 * Provides an easy way to map URLs to classes. URLs can be literal
	 * strings or regular expressions.
	 *
	 * When the URLs are processed:
	 *	  * deliminators (/) are automatically escaped: (\/)
	 *	  * The beginning and end are anchored (^ $)
	 *	  * An optional end slash is added (/?)
	 *		* The i option is added for case-insensitive searches
	 *
	 * Example:
	 *
	 * $urls = array(
	 *	 '/' => 'index',
	 *	 '/page/(\d+) => 'page'
	 * );
	 *
	 * class page {
	 *	  function GET($matches) {
	 *		  echo "Your requested page " . $matches[1];
	 *	  }
	 * }
	 *
	 * glue::stick($urls);
	 *
	 */
	class glue {

		/**
		 * stick
		 *
		 * the main static function of the glue class.
		 *
		 * @param   array		$urls  		The regex-based url to class mapping
		 * @param   string		$base  		Base url if not at root 
		 * @throws  Exception			   Thrown if corresponding class is not found
		 * @throws  Exception			   Thrown if no match is found
		 * @throws  BadMethodCallException  Thrown if a corresponding GET,POST is not found
		 *
		 */
		static function stick ($urls, $base = NULL) {
			$method = strtoupper($_SERVER['REQUEST_METHOD']);
			$path = $_SERVER['REQUEST_URI'];

			// Trim any manual GET parameters off.
			$path = explode('?', $path);
			$path = $path[0];

			if($base != NULL) {
				$path = substr($path, strpos($path, $base)+strlen($base));
			}

			$found = false;

			krsort($urls);

			foreach ($urls as $regex => $class) {
				$regex = str_replace('/', '\/', $regex);
				$regex = '^' . $regex . '\/?$';

				if (preg_match("/$regex/i", $path, $matches)) {
					$found = true;
					if (class_exists($class)) {
						$obj = new $class;
						if (method_exists($obj, $method)) {
							$obj->$method($matches);
						} else {
							throw new GlueMethodException("Could not find specified method in the class", $path, $class, $method);
						}
					} else {
						throw new GlueInternalException("Could not find specified class", $path, $class, $method);
					}
					break;
				}
			}
			if (!$found) {
				throw new GlueURLException("The URL accessed does not match any URL in the glue", $path);
			}
		}
	}

{'fraction_non_alphanumeric': 0.14839449541284402, 'fraction_numerical': 0.0006880733944954129, 'mean_word_length': 2.4943910256410255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5848680', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1382, 'n_words': 443}