Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class route{
- private $hits, $hit;
- public function __construct($url){
- $this -> getRoutes();
- foreach($this -> hits as $class => $actions){
- foreach($actions as $k => $function){
- preg_match_all("/(:([a-z]+)?)/i", $k, $fields);
- if(count($fields))
- $k = $this -> clean(preg_replace("/(:([a-z]+)?)/i", "([a-z|0-9]+)", $k));
- preg_match_all("/$k/i", $url, $match);
- if(count($match[0])){
- foreach($fields[2] as $k => $v)
- $params[$v] = $match[$k + 1][0];
- $this -> hit -> ctrlClass = $class;
- $this -> hit -> ctrlFunction = $function;
- $this -> hit -> params = (is_null($params)?array():$params);
- }
- }
- }
- }
- public function get(){
- return $this -> hit;
- }
- private function getRoutes(){
- $files = scandir("src");
- foreach($files as $file){
- if(is_file("src/$file")){
- $class = explode(".", $file);
- $this -> hits[$class[0]] = array();
- $content = file_get_contents("src/$file");
- preg_match_all("/\# url\(([a-z|\/|:|0-9]+)\) function\(([a-z|\/|:|0-9]+)\)/i", $content, $matches);
- foreach($matches[1] as $k => $v)
- $this -> hits[$class[0]][$v] = $matches[2][$k];
- }
- }
- }
- private function clean($string){
- return str_replace("/", "\/", $string);
- }
- }
- class user extends main{
- # url(user/set) function(set)
- public function set(){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement