From 23a9d7c4d0929dd1ecef00f6afb86ea455bbf234 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Mon, 15 Aug 2022 15:30:47 +0200
Subject: [PATCH] update router class

---
 src/tinyrouter.class.php | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/tinyrouter.class.php b/src/tinyrouter.class.php
index 1be3d99..947c42a 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
-- 
GitLab