VERSION UPDATE: beta 0.6.0 see the readme.md document
This commit is contained in:
@@ -17,6 +17,7 @@ class Router extends Config
|
||||
private static $_cur_page;
|
||||
private static $_routes = array();
|
||||
private static $_action;
|
||||
private static $_page_params = array();
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
@@ -95,6 +96,7 @@ class Router extends Config
|
||||
*/
|
||||
private static function setAction( $action )
|
||||
{
|
||||
self::$_action = $action;
|
||||
$_REQUEST['_action'] = $action;
|
||||
}
|
||||
|
||||
@@ -114,17 +116,24 @@ class Router extends Config
|
||||
}
|
||||
|
||||
public function tplName($ending = false)
|
||||
{
|
||||
self::setCurPage();
|
||||
if($ending)
|
||||
{
|
||||
return self::getCurPage() . ".tpl";
|
||||
}
|
||||
else
|
||||
{
|
||||
return self::getCurPage();
|
||||
}
|
||||
}
|
||||
{
|
||||
preg_match('/\/'.self::getCurPage().'\//', $_SERVER['REQUEST_URI'], $matches);
|
||||
if(!array_key_exists(0, $matches))
|
||||
{
|
||||
self::setCurPage();
|
||||
}
|
||||
if($ending)
|
||||
{
|
||||
self::setPageParams( $_SERVER["REQUEST_URI"] );
|
||||
return self::getCurPage() . ".tpl";
|
||||
}
|
||||
else
|
||||
{
|
||||
self::setPageParams( $_SERVER["REQUEST_URI"] );
|
||||
return self::getCurPage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -134,34 +143,113 @@ class Router extends Config
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $cur_page
|
||||
*/
|
||||
private static function setCurPage( )
|
||||
{
|
||||
if( self::getCurRoute() == null )
|
||||
{
|
||||
$uri_parts = explode('/', $_SERVER["REQUEST_URI"]);
|
||||
if(is_array($uri_parts))
|
||||
{
|
||||
if($uri_parts[1] == "")
|
||||
{
|
||||
self::$_cur_page = "index";
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_cur_page = $uri_parts[1];
|
||||
if(array_key_exists(2, $uri_parts))
|
||||
{
|
||||
self::setAction($uri_parts[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_cur_page = self::getCurRoute();
|
||||
}
|
||||
}
|
||||
* @desc sets the current page route in the router
|
||||
*/
|
||||
private static function setCurPage( )
|
||||
{
|
||||
$params = false;
|
||||
$uri_parts = explode('/', $_SERVER["REQUEST_URI"]);
|
||||
if(is_array($uri_parts))
|
||||
{
|
||||
if($uri_parts[1] == "")
|
||||
{
|
||||
self::$_cur_page = "index";
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_cur_page = $uri_parts[1];
|
||||
if(array_key_exists(2, $uri_parts))
|
||||
{
|
||||
self::setAction($uri_parts[2]);
|
||||
$params = true;
|
||||
}
|
||||
}
|
||||
if($params)
|
||||
{
|
||||
self::setPageParams( $uri_parts );
|
||||
}
|
||||
}
|
||||
if( self::getCurRoute() != null )
|
||||
{
|
||||
self::$_cur_page = self::getCurRoute();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @desc will get the current page parameters concerning url parts
|
||||
* e.g. Controller/Action/Param
|
||||
* @return array
|
||||
*/
|
||||
public function getPageParams()
|
||||
{
|
||||
return self::$_page_params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $page_params
|
||||
*/
|
||||
private static function setPageParams( $uri_parts )
|
||||
{
|
||||
$skip = false;
|
||||
if(is_array($uri_parts))
|
||||
{
|
||||
for($i=2;sizeof($uri_parts)>$i;$i++)
|
||||
{
|
||||
if(is_string($uri_parts[$i]))
|
||||
{
|
||||
if(array_key_exists($i+1, $uri_parts))
|
||||
{
|
||||
if(!is_numeric($uri_parts[$i]))
|
||||
{
|
||||
foreach(self::getRoutes()['route'] as $routing)
|
||||
{
|
||||
if(stristr($routing, '/' . self::getCurPage() . '/'.self::getAction().'/'))
|
||||
{
|
||||
preg_match('/\{(.*?)\}/', $routing, $matches);
|
||||
preg_match('/\/' . self::getCurPage() . '\/' . self::getAction() . '\/\d+/', $_SERVER["REQUEST_URI"], $routematch);
|
||||
if(is_array($routematch))
|
||||
{
|
||||
if(array_key_exists(0, $routematch))
|
||||
{
|
||||
$param_key = $matches[1];
|
||||
$param = $routematch[0];
|
||||
if(is_string($param_key))
|
||||
{
|
||||
if(!$skip && !array_key_exists($param_key, $_REQUEST[$uri_parts[$i]] ))
|
||||
{
|
||||
preg_match('|\d+|', $param, $digit);
|
||||
$_REQUEST[$uri_parts[$i]] = array($param_key => $digit[0]);
|
||||
$skip = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($skip)
|
||||
{
|
||||
if(!array_key_exists($uri_parts[$i], $_REQUEST))
|
||||
{
|
||||
$_REQUEST[$uri_parts[$i]] = $uri_parts[$i + 1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!array_key_exists($uri_parts[$i], $_REQUEST))
|
||||
{
|
||||
$_REQUEST[$uri_parts[$i]] = $uri_parts[$i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self::$_page_params = $_REQUEST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with all the information about the current page
|
||||
|
||||
Reference in New Issue
Block a user