<?php
namespace Thirty; class Router{ private $routes=[]; public function get($p,$h){$this->routes['GET'][$p]=$h;} public function post($p,$h){$this->routes['POST'][$p]=$h;} public function dispatch($m,$path){ $b=rtrim((string)(function_exists('env')?env('APP_BASE',''):''),'/'); if($b!==''&&strpos($path,$b)===0){ $path=substr($path,strlen($b)); } $path=rtrim($path,'/'); if($path==='') $path='/'; $h=$this->routes[$m][$path]??null; if(!$h){ http_response_code(404); echo 'Ruta no encontrada'; return;} call_user_func($h);} }
