Selaa lähdekoodia

Add route reporting information

Nathaniel van Diepen 6 vuotta sitten
vanhempi
commit
d92038d180
4 muutettua tiedostoa jossa 36 lisäystä ja 4 poistoa
  1. 2 1
      App/path.class.php
  2. 14 1
      App/router.class.php
  3. 1 1
      Data/template.class.php
  4. 19 1
      app.class.php

+ 2 - 1
App/path.class.php

@@ -33,6 +33,7 @@
 		}
 		public function jsonSerialize(){
 			return [
+				'path'=>$this->path,
 				'dypath'=>$this->path
 			];
 		}
@@ -50,4 +51,4 @@
 			return $this->path->args($path);
 		}
 	}
-?>
+?>

+ 14 - 1
App/router.class.php

@@ -31,6 +31,19 @@
 				case 'handled':
 					return $this->_handled;
 				break;
+				case 'routes':
+					$routes = [];
+					$base = rtrim($this->_base, '/');
+					foreach($this->_paths as $path){
+						$routes[] = $base.$path->path;
+					}
+					foreach($this->_routers as $router){
+						foreach($router->routes as $route){
+							$routes[] = $base.$route;
+						}
+					}
+					return $routes;
+				break;
 			}
 		}
 		public function __clone(){
@@ -213,4 +226,4 @@
 			return $res;
 		}
 	}
-?>
+?>

+ 1 - 1
Data/template.class.php

@@ -301,4 +301,4 @@
 			return static::$templates;
 		}
 	}
-?>
+?>

+ 19 - 1
app.class.php

@@ -61,6 +61,24 @@
 				parent::__destruct();
 			}
 		}
+		public function __get(string $name){
+			switch($name){
+				case 'routes':
+					$routes = $this->router->routes;
+					foreach($this->routers as $prefix => $router){
+						foreach($router->routes as $route){
+							$routes[] = $prefix.$route;
+						}
+					}
+					foreach($this->domains as $domain => $router){
+						foreach($router->routes as $route){
+							$routes[] = $domain.$route;
+						}
+					}
+					return $routes;
+				break;
+			}
+		}
 		public static function import_all(string $dirpath){
 			foreach(scandir($dirpath) as $file){
 				$path = "{$dirpath}/{$file}";
@@ -251,4 +269,4 @@
 		ini_set('display_errors', 'Off');
 		gc_enable();
 	}
-?>
+?>