Skip to content
Snippets Groups Projects
Commit 23a9d7c4 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update router class

parent 8508404d
No related branches found
No related tags found
No related merge requests found
......@@ -24,11 +24,13 @@
*
**/
class tinyrouter{
namespace iml;
class tinyrouter{
public $sUrl = '';
public $sMethod = '';
public $aRoutes = [];
public $aMatch = false;
/**
* constructor
......@@ -40,6 +42,10 @@
$this->setUrl($sUrl);
}
// ----------------------------------------------------------------------
// protected functions
// ----------------------------------------------------------------------
/**
* detect last matching route item
* if no route matches then it returns false
......@@ -87,6 +93,8 @@
}
if($bFoundRoute){
$aReturn=[
"request-method"=>(isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false),
"request-url"=>$this->sUrl,
"route"=>$aRoutecfg[0],
"callback"=>$aRoutecfg[1],
"vars"=>$aVars
......@@ -98,9 +106,14 @@
return $this->aMatch;
}
// ----------------------------------------------------------------------
// public functions :: setter
// ----------------------------------------------------------------------
/**
* set routes
* @param array $aRoutes list of [ route, more params ... ]
* @return boolean
*/
public function setRoutes($aRoutes=[]){
if(is_array($aRoutes) && count($aRoutes)){
......@@ -112,12 +125,18 @@
/**
* set incoming url
* @param string sUrl url to fetch; https://api.exaple.com/
*/
public function setUrl($sUrl){
$this->sUrl=$sUrl;
$this->_getRoute();
return true;
}
// ----------------------------------------------------------------------
// public functions :: getter
// ----------------------------------------------------------------------
/**
* helper function: get url parts as array
* @returns array
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment