Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?php
  2. class route{
  3. private $hits, $hit;
  4. public function __construct($url){
  5. $this -> getRoutes();
  6. foreach($this -> hits as $class => $actions){
  7. foreach($actions as $k => $function){
  8. preg_match_all("/(:([a-z]+)?)/i", $k, $fields);
  9. if(count($fields))
  10. $k = $this -> clean(preg_replace("/(:([a-z]+)?)/i", "([a-z|0-9]+)", $k));
  11. preg_match_all("/$k/i", $url, $match);
  12. if(count($match[0])){
  13. foreach($fields[2] as $k => $v)
  14. $params[$v] = $match[$k + 1][0];
  15. $this -> hit -> ctrlClass = $class;
  16. $this -> hit -> ctrlFunction = $function;
  17. $this -> hit -> params = (is_null($params)?array():$params);
  18. }
  19. }
  20. }
  21. }
  22.  
  23. public function get(){
  24. return $this -> hit;
  25. }
  26.  
  27. private function getRoutes(){
  28. $files = scandir("src");
  29. foreach($files as $file){
  30. if(is_file("src/$file")){
  31. $class = explode(".", $file);
  32. $this -> hits[$class[0]] = array();
  33. $content = file_get_contents("src/$file");
  34. preg_match_all("/\# url\(([a-z|\/|:|0-9]+)\) function\(([a-z|\/|:|0-9]+)\)/i", $content, $matches);
  35. foreach($matches[1] as $k => $v)
  36. $this -> hits[$class[0]][$v] = $matches[2][$k];
  37. }
  38. }
  39. }
  40.  
  41. private function clean($string){
  42. return str_replace("/", "\/", $string);
  43. }
  44. }
  45.  
  46. class user extends main{
  47. # url(user/set) function(set)
  48. public function set(){
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement