<commit_before><?php
/**
 * 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
 */

namespace Fuel;

use Fuel\Application as App;

class 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(static::$routes['default']) || static::$routes['default'] == '')
			{
				// TODO: write logic to deal with missing default route.
				return FALSE;
			}
			else
			{
				return static::parse_match(static::$routes['default']);
			}
		}

		foreach (static::$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 static::parse_match($route, $params);
			}
		}
		
		return static::parse_match($uri->uri);
	}

	/**
	 * Parse module routes
	 *
	 * This first adds the given routes to the current loaded routes and then
	 * reparses the given uri.
	 *
	 * @param	string	current module name
	 * @param	array	new routes
	 * @param	string	uri to reparse
	 * @return	array	parsed routing info
	 */
	public static function parse_module($module, Array $routes, $current_uri)
	{
		// Load module routes and add to router
		foreach ($routes as $uri => $route)
		{
			$prefix = in_array($uri, array('404')) ? '' : $module.'/';
			if ($uri == 'default')
			{
				static::$routes[$module] = $prefix.$route;
			}
			else
			{
				static::$routes[$prefix.$uri] = $prefix.$route;
			}
		}

		// Reroute with module routes
		$route = static::parse($current_uri);
		// Remove first segment, that's the module
		array_shift($route['segments']);

		return $route;
	}
	
	/**
	 * Parses a route match and returns the controller, action and params.
	 *
	 * @access	protected
	 * @param	string	The matched route
	 * @return	array
	 */<commit_msg>Disabled default routing in modules, is done by convention like with directories (default = same name).<commit_after><?php
/**
 * 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
 */

namespace Fuel;

use Fuel\Application as App;

class 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(static::$routes['default']) || static::$routes['default'] == '')
			{
				// TODO: write logic to deal with missing default route.
				return FALSE;
			}
			else
			{
				return static::parse_match(static::$routes['default']);
			}
		}

		foreach (static::$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 static::parse_match($route, $params);
			}
		}
		
		return static::parse_match($uri->uri);
	}

	/**
	 * Parse module routes
	 *
	 * This first adds the given routes to the current loaded routes and then
	 * reparses the given uri.
	 *
	 * @param	string	current module name
	 * @param	array	new routes
	 * @param	string	uri to reparse
	 * @return	array	parsed routing info
	 */
	public static function parse_module($module, Array $routes, $current_uri)
	{
		// Load module routes and add to router
		foreach ($routes as $uri => $route)
		{
			$prefix = in_array($uri, array('404')) ? '' : $module.'/';
			static::$routes[$prefix.$uri] = $prefix.$route;
		}

		// Reroute with module routes
		$route = static::parse($current_uri);
		// Remove first segment, that's the module
		array_shift($route['segments']);

		return $route;
	}
	
	/**
	 * Parses a route match and returns the controller, action and params.
	 *
	 * @access	protected
	 * @param	string	The matched route
	 * @return	array
	 */
{'fraction_non_alphanumeric': 0.1634199134199134, 'fraction_numerical': 0.004761904761904762, 'mean_word_length': 3.2589861751152074, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '1850992', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1498, 'n_words': 446}