Home Files
Adminer
Execute Command
PHP Eval
Symlink
File Upload
Owner :
www-data
PHP Version
8.1.8
Disk Space
203.89 GB
Server Addr
171.9.3.2
Your IP
171.9.3.1
Edit File
File:
<?php class Router { private $routes = []; /** * Adiciona uma nova rota * * @param String $route */ public function add($route) { preg_match_all('{\{[a-z][a-zA-Z0-9_]*}', $route, $variable); preg_match_all('{[^\{][a-z][a-zA-Z0-9_]*}', $route, $static); $variable[0] = $this->trimArray('{', $variable[0]); $static[0] = $this->trimArray('/', $static[0]); $this->routes[$route]['variable'] = $variable[0]; $this->routes[$route]['static']['order'] = $static[0]; $this->routes[$route]['static']['values'] = array_diff($static[0], $variable[0]); } /** * Retorna os parâmetros configurados da rota * Ou null caso não seja encontrada uma rota válida * * @param String $url [description] */ public function params($url) { $result = []; $clean = ltrim ($url, '/'); $params = explode('/', $clean); foreach ($this->routes as $route) { $params = array_diff($params, $route['static']['values']); if (count($params) == count($route['variable'])) { return array_combine($route['variable'], $params); } } } /** * Remove um ou mais caracteres de strings em um array * em um ambiente ideal isso seria um trait ou arquivo * de funções */ protected function trimArray($str, $data) { $array_fill = array_fill(0, count($data), $str); return array_map( function($v, $str) {return ltrim($v, $str);}, $data, $array_fill ); } }