<commit_before><?php
/**
 *
 * @package     OpenFlame Web Framework
 * @copyright   (c) 2010 OpenFlameCMS.com
 * @license     http://opensource.org/licenses/mit-license.php The MIT License
 * @link        https://github.com/OpenFlame/OpenFlame-Framework
 *
 * Minimum Requirement: PHP 5.3.0
 */

namespace OpenFlame\Framework\URL;

if(!defined('OpenFlame\\Framework\\ROOT_PATH')) exit;

/**
 * OpenFlame Web Framework - Static URL router route instance,
 * 	     A route instance for the static URL router, provides abstraction of request verification.
 *
 *
 * @license     http://opensource.org/licenses/mit-license.php The MIT License
 * @link        https://github.com/OpenFlame/OpenFlame-Framework
 */
class RouteInstance
{
	protected $route_map = array();

	protected $route_regexp = '';

	protected $route_base = '';

	protected $serialized_route = '';

	protected $request_data;

	//protected $route_callback;

	private static $supported_types = array(
		'str'		=> true,
		'string'	=> true,
		'float'		=> true,
		'int'		=> true,
		'integer'	=> true,
	);

	public static function newInstance()
	{
		return new static();
	}

	public function getRouteBase()
	{
		return $this->route_base;
	}

	protected function setRouteBase($base)
	{
		// reset the serialized route on any changes to the route...
		$this->setSerializedRoute(NULL);
		$this->route_base = $base;
		return $this;
	}

	public function getRouteMap()
	{
		return $this->route_map;
	}

	protected function setRouteMap(array $map)
	{
		// reset the serialized route on any changes to the route...
		$this->setSerializedRoute(NULL);
		$this->route_map = $map;
		return $this;
	}

	public function getRouteRegexp()
	{
		return $this->route_regexp;
	}

	protected function setRouteRegexp($regexp)
	{
		// reset the serialized route on any changes to the route...
		$this->setSerializedRoute(NULL);
		$this->route_regexp = $regexp;
		return $this;
	}

	public function getSerializedRoute()
	{
		if(empty($this->serialized_route))
		{
			$route_array = array(
				'route_base'	=> $this->getRouteBase(),
				'route_map'		=> $this->getRouteMap(),
				'route_regexp'	=> $this->getRouteRegexp(),
			);

			$this->setSerializedRoute(serialize($route_array));
		}

		return $this->serialized_route;
	}

	protected function setSerializedRoute($route_string)
	{
		$this->serialized_route = $route_string;
		return $this;
	}

	final public function getTypeSupported($type)
	{
		return isset(self::$supported_types[$type]);
	}

	public function loadRawRoute($route)
	{
		$route_data = explode('/', $route, \OpenFlame\Framework\URL\Router::EXPLODE_LIMIT);

		$this->setRouteBase($route_data[0])
			->setRouteMap($this->buildRouteMap($route_data))
			->setRouteRegexp($this->buildRouteRegex());

		return $this;
	}

	public function loadSerializedRoute($route_string)
	{
		$route_data = unserialize($route_string);

		// Protected against bunk data
		if($route_data === false || !isset($route_data['route_base']) || !isset($route_data['route_map']) || !isset($route_data['route_regexp']))
		{
			throw new \RuntimeException('Route unserialization failed, data extracted is invalid or incomplete');
		}

		// Load the route data seamlessly
		$this->setRouteBase($route_data['route_base'])
			->setRouteMap($route_data['route_map'])
			->setRouteRegexp($route_data['route_regexp'])
			->setSerializedRoute($route_string);

		return $this;
	}

	// does the request match this route?
	public function verify($request)
	{
		// array - $request
		// asdf
	}

	// extract data using the regexp from the request
	public function loadRequest($request)
	{
		// array - $request
		// asdf
	}

	// will grab extracted data from the request
	public function getDataPoint($point)
	{
		// asdf
	}

	protected function buildRouteMap(array $route_data)
	{
		// example format:
		// "$var:string"
		// the value for the request component is stored in entry "var", and is typecast as string<commit_msg>Looks like we need to make use of the route_callback, derr<commit_after><?php
/**
 *
 * @package     OpenFlame Web Framework
 * @copyright   (c) 2010 OpenFlameCMS.<EMAIL>
 * @license     http://opensource.org/licenses/mit-license.php The MIT License
 * @link        https://github.com/OpenFlame/OpenFlame-Framework
 *
 * Minimum Requirement: PHP 5.3.0
 */

namespace OpenFlame\Framework\URL;

if(!defined('OpenFlame\\Framework\\ROOT_PATH')) exit;

/**
 * OpenFlame Web Framework - Static URL router route instance,
 * 	     A route instance for the static URL router, provides abstraction of request verification.
 *
 *
 * @license     http://opensource.org/licenses/mit-license.php The MIT License
 * @link        https://github.com/OpenFlame/OpenFlame-Framework
 */
class RouteInstance
{
	protected $route_map = array();

	protected $route_regexp = '';

	protected $route_base = '';

	protected $serialized_route = '';

	protected $request_data;

	protected $route_callback;

	private static $supported_types = array(
		'str'		=> true,
		'string'	=> true,
		'float'		=> true,
		'int'		=> true,
		'integer'	=> true,
	);

	public static function newInstance()
	{
		return new static();
	}

	public function getRouteBase()
	{
		return $this->route_base;
	}

	protected function setRouteBase($base)
	{
		// reset the serialized route on any changes to the route...
		$this->setSerializedRoute(NULL);
		$this->route_base = $base;
		return $this;
	}

	public function getRouteMap()
	{
		return $this->route_map;
	}

	protected function setRouteMap(array $map)
	{
		// reset the serialized route on any changes to the route...
		$this->setSerializedRoute(NULL);
		$this->route_map = $map;
		return $this;
	}

	public function getRouteRegexp()
	{
		return $this->route_regexp;
	}

	protected function setRouteRegexp($regexp)
	{
		// reset the serialized route on any changes to the route...
		$this->setSerializedRoute(NULL);
		$this->route_regexp = $regexp;
		return $this;
	}

	public function getRouteCallback()
	{
		return $this->route_callback;
	}

	public function setRouteCallback($callback)
	{
		// reset the serialized route on any changes to the route...
		$this->setSerializedRoute(NULL);
		if(strpos($callback, '->') !== false)
		{
			list($class, $method) = explode('->', $callback, 2);
			$this->route_callback = array(
				'callback'		=> array($class, $method),
				'object'		=> true,
				'static'		=> false,
			);
		}
		elseif(strpos($callback, '::') !== false)
		{
			$this->route_callback = array(
				'callback'		=> $callback,
				'object'		=> true,
				'static'		=> true,
			);
		}
		else
		{
			$this->route_callback = array(
				'callback'		=> $callback,
				'object'		=> false,
				'static'		=> false,
			);
		}

		return $this;
	}

	public function getSerializedRoute()
	{
		if(empty($this->serialized_route))
		{
			$route_array = array(
				'route_base'		=> $this->getRouteBase(),
				'route_map'			=> $this->getRouteMap(),
				'route_regexp'		=> $this->getRouteRegexp(),
				'route_callback'	=> $this->getRouteCallback(),
			);

			$this->setSerializedRoute(serialize($route_array));
		}

		return $this->serialized_route;
	}

	protected function setSerializedRoute($route_string)
	{
		$this->serialized_route = $route_string;
		return $this;
	}

	final public function getTypeSupported($type)
	{
		return isset(self::$supported_types[$type]);
	}

	public function loadRawRoute($route)
	{
		$route_data = explode('/', $route, \OpenFlame\Framework\URL\Router::EXPLODE_LIMIT);

		$this->setRouteBase($route_data[0])
			->setRouteMap($this->buildRouteMap($route_data))
			->setRouteRegexp($this->buildRouteRegex());

		return $this;
	}

	public function loadSerializedRoute($route_string)
	{
		$route_data = unserialize($route_string);

		// Protected against bunk data
		if($route_data === false || !isset($route_data['route_base']) || !isset($route_data['route_map']) || !isset($route_data['route_regexp']) || !isset($route_data['route_callback']))
		{
			throw new \RuntimeException('Route unserialization failed, data extracted is invalid or incomplete');
		}

		// Load the route data seamlessly
		$this->setRouteBase($route_data['route_base'])
			->setRouteMap($route_data['route_map'])
			->setRouteRegexp($route_data['route_regexp'])
			->setRouteCallback($route_data['route_callback'])
			->setSerializedRoute($route_string);

		return $this;
	}

	// does the request match this route?
	public function verify($request)
	{
		// array - $request
		// asdf
	}

	// extract data using the regexp from the request
	public function loadRequest($request)
	{
		// array - $request
		// asdf
	}

	// execute the stored callback
	public function fireCallback()
	{
		// asdf
	}

	// will grab extracted data from the request
	public function getDataPoint($point)
	{
		// asdf
	}

	protected function buildRouteMap(array $route_data)
	{
		// example format:
		// "$var:string"
		// the value for the request component is stored in entry "var", and is typecast as string
{'fraction_non_alphanumeric': 0.1416395648760794, 'fraction_numerical': 0.0019064707861388358, 'mean_word_length': 3.8892543859649122, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 89, 'https://': 4, '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': '2842165', 'n_tokens_mistral': 3176, 'n_tokens_neox': 2890, 'n_words': 665}