<commit_before><?php defined('COREPATH') or die('No direct script access.');
/**
 * Fuel
 *
 * Fuel is a fast, lightweight, community driven PHP5 framework.
 *
 * @package		Fuel
 * @version		1.0
 * @author		Fuel Development Team
 * @license		MIT License
 * @copyright	2010 <NAME>
 * @link		http://fuelphp.com
 */

class Fuel_Route {
	
	public static $routes = array();

	/**
	 * Attemptes to find the correct route for the given URI
	 *
	 * @access	public
	 * @param	object	The URI object
	 * @return	array
	 */
	public static function parse($uri)
	{
		// This handles the default route
		if ($uri->uri == '')
		{
			if ( ! isset(Route::$routes['default']) || Route::$routes['default'] == '')
			{
				// TODO: write logic to deal with missing default route.
				return FALSE;
			}
			else
			{
				return Route::parse_match(Route::$routes['default']);
			}
		}

		foreach (Route::$routes as $search => $route)
		{
			$search = str_replace(array(':any', ':segment'), array('.+', '[^/]+'), $search);
			$search = preg_replace('#:([a-z]+)#uD', '(?P<$1>.+)', $search);

			if (preg_match('#'.$search.'#uD', $uri->uri, $params) != false)
			{
				$route = preg_replace('#'.$search.'#uD', $route, $uri->uri);

				return Route::parse_match($route, $params);
			}
		}
		
		return Route::parse_match($uri->uri);
	}
	
	/**
	 * Parses a route match and returns the controller, action and params.
	 *
	 * @access	protected
	 * @param	string	The matched route
	 * @return	array
	 */
	protected static function parse_match($route, $named_params = array())
	{
		$method_params = array();

		$segments = array_pad(explode('/', $route), 2, 'index');
		
		if (count($segments) > 2)
		{
			$method_params = $segments;
			array_shift($method_params);
			array_shift($method_params);
		}

		// Clean out all the non-named stuff out of $named_params
		foreach($named_params as $key => $val)
		{
			if ( ! is_numeric($named_params))
			{
				$named_params[$key] = $val;
			}
		}

		return array(
			'uri'			=> $route,
			'controller'	=> $segments[0],
			'action'		=> $segments[1],
			'method_params'	=> $method_params,
			'named_params'	=> $named_params,<commit_msg>Removed multiple array_shifts and replaced it with an array_slice.<commit_after><?php defined('COREPATH') or die('No direct script access.');
/**
 * Fuel
 *
 * Fuel is a fast, lightweight, community driven PHP5 framework.
 *
 * @package		Fuel
 * @version		1.0
 * @author		Fuel Development Team
 * @license		MIT License
 * @copyright	2010 <NAME>
 * @link		http://fuelphp.com
 */

class Fuel_Route {
	
	public static $routes = array();

	/**
	 * Attemptes to find the correct route for the given URI
	 *
	 * @access	public
	 * @param	object	The URI object
	 * @return	array
	 */
	public static function parse($uri)
	{
		// This handles the default route
		if ($uri->uri == '')
		{
			if ( ! isset(Route::$routes['default']) || Route::$routes['default'] == '')
			{
				// TODO: write logic to deal with missing default route.
				return FALSE;
			}
			else
			{
				return Route::parse_match(Route::$routes['default']);
			}
		}

		foreach (Route::$routes as $search => $route)
		{
			$search = str_replace(array(':any', ':segment'), array('.+', '[^/]+'), $search);
			$search = preg_replace('#:([a-z]+)#uD', '(?P<$1>.+)', $search);

			if (preg_match('#'.$search.'#uD', $uri->uri, $params) != false)
			{
				$route = preg_replace('#'.$search.'#uD', $route, $uri->uri);

				return Route::parse_match($route, $params);
			}
		}
		
		return Route::parse_match($uri->uri);
	}
	
	/**
	 * Parses a route match and returns the controller, action and params.
	 *
	 * @access	protected
	 * @param	string	The matched route
	 * @return	array
	 */
	protected static function parse_match($route, $named_params = array())
	{
		$method_params = array();

		$segments = array_pad(explode('/', $route), 2, 'index');
		
		if (count($segments) > 2)
		{
			$method_params = array_slice($segments, 2);
		}

		// Clean out all the non-named stuff out of $named_params
		foreach($named_params as $key => $val)
		{
			if ( ! is_numeric($named_params))
			{
				$named_params[$key] = $val;
			}
		}

		return array(
			'uri'			=> $route,
			'controller'	=> $segments[0],
			'action'		=> $segments[1],
			'method_params'	=> $method_params,
			'named_params'	=> $named_params,
{'fraction_non_alphanumeric': 0.17927823050058206, 'fraction_numerical': 0.005820721769499418, 'mean_word_length': 3.3881511746680286, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6510141', 'n_tokens_mistral': 1687, 'n_tokens_neox': 1470, 'n_words': 372}