Setting up my convoluted web parsing structure... in short:
[glcas.git] / libglcas / urlparser.php
1 <?php
2
3 // the purpose of this plugin is to take a url and figure out the owning class that should be called
4 error_log("glcasurlparser loaded");
5
6 class GLCASUrlParser {
7         function __construct($urlconfig, $config)
8         {
9                 $v = print_r($urlconfig, true);
10                 error_log("constructor for urlparser, $v");
11                 $this->urlClasses = $urlconfig;
12                 $this->config = $config;
13         }
14         
15         function getClass($url)
16         {
17                 error_log("getclass for $url");
18                 //echo "<pre>URL CLasses";
19                 //print_r($this->urlClasses);
20                 //echo "</pre>";
21                 $default = "";
22                 $base = "";
23                 if(is_array($this->urlClasses)) {
24                         foreach($this->urlClasses as $key => $val) {
25                                 error_log("checking url $url against $key, $val");
26                                 if($url == "/") {
27                                         $base = $val;
28                                         error_log("base set to $val");
29                                         return new $val($this->config);
30                                 } 
31                                 
32                                 // TODO: this is quite messy really, need to think about how i do /'s in urls for url parsers
33                                 if($key=="*") {
34                                         $default = $val;
35                                         error_log("catchall set to $val");
36                                 } else if($key != "/") {
37                                         // now the rest
38                                         if(preg_match("/$key/", $url)) {
39                                                 error_log("matched $url to $key and $val");
40                                                 return new $val($this->config);
41                                         }
42                                 }
43                         }
44                 }
45                 error_log("get class returns default");
46                 return new $default($this->config);
47         }
48         
49         private $urlClasses;
50         private $config;
51 }
52
53 ?>