diff --git a/src/tinyrouter.class.php b/src/tinyrouter.class.php index 1be3d996f30acbaadcd1758db4ff2e4ba6bf09c3..947c42a99eccdf9485052a564611f277c0cbd900 100644 --- a/src/tinyrouter.class.php +++ b/src/tinyrouter.class.php @@ -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