|
@@ -51,41 +51,38 @@
|
|
|
$this->_paths = array();
|
|
|
}
|
|
|
public function handle($url,$res = null,$fn = null,$onerror = null){
|
|
|
- if(strpos($url,$this->_base) !== false){
|
|
|
- $url = substr($url,strpos($url,$this->_base)+strlen($this->_base));
|
|
|
- if($url[0] != '/'){
|
|
|
- $url = '/'.$url;
|
|
|
- }
|
|
|
- if(is_null($res)){
|
|
|
- $res = new Response($url);
|
|
|
- }else{
|
|
|
- $res->url = $url;
|
|
|
- }
|
|
|
- if(!in_array($res,$this->responses)){
|
|
|
- array_push($this->responses,$res);
|
|
|
- }
|
|
|
- ob_start();
|
|
|
- $handled = false;
|
|
|
- foreach($this->_paths as $k => $p){
|
|
|
- if($p->matches($url)){
|
|
|
- $handled = true;
|
|
|
- try{
|
|
|
- $p($res,$p->args($url));
|
|
|
- }catch(Exception $e){
|
|
|
- if(!is_null($onerror)){
|
|
|
- $onerror($res,$e);
|
|
|
- }else{
|
|
|
- throw $e;
|
|
|
- }
|
|
|
+ if($url[0] != '/'){
|
|
|
+ $url = '/'.$url;
|
|
|
+ }
|
|
|
+ if(is_null($res)){
|
|
|
+ $res = new Response($url);
|
|
|
+ }else{
|
|
|
+ $res->url = $url;
|
|
|
+ }
|
|
|
+ if(!in_array($res,$this->responses)){
|
|
|
+ array_push($this->responses,$res);
|
|
|
+ }
|
|
|
+ ob_start();
|
|
|
+ $handled = false;
|
|
|
+ foreach($this->_paths as $k => $p){
|
|
|
+ if($p->matches($url)){
|
|
|
+ $handled = true;
|
|
|
+ try{
|
|
|
+ $p($res,$p->args($url));
|
|
|
+ }catch(Exception $e){
|
|
|
+ if(!is_null($onerror)){
|
|
|
+ $onerror($res,$e);
|
|
|
+ }else{
|
|
|
+ throw $e;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(!$handled && !is_null($fn)){
|
|
|
- $fn($res,$url);
|
|
|
- }
|
|
|
- $res->output = ob_get_contents();
|
|
|
- ob_end_clean();
|
|
|
}
|
|
|
+ if(!$handled && !is_null($fn)){
|
|
|
+ $fn($res,$url);
|
|
|
+ }
|
|
|
+ $res->output = ob_get_contents();
|
|
|
+ ob_end_clean();
|
|
|
return $res;
|
|
|
}
|
|
|
}
|