Example #1
0
File: perry.php Project: rk/perry
 /**
  * This method handles a given request. It attempts to match a route to the URI, and if it
  * fails to do so the response defaults to the Perry::not_found() method.
  *
  * @see Perry::get()
  * @see Perry::trigger_filters()
  * @see Request::matches()
  * @param Request $request 
  * @return void
  * @author Robert Kosek
  */
 public function handle(Request $request)
 {
     $uri = $request->uri;
     $verb = $request->method;
     $callback = array($this, 'not_found');
     $params = array();
     if (isset($this->routes[$verb][$uri])) {
         $callback = $this->routes[$verb][$uri]['callback'];
     } else {
         foreach ($this->routes[$verb] as $pattern => $route_data) {
             if ($pattern[0] == '%' && $request->matches($pattern, $matches)) {
                 $data = array_select_values_of($matches, $route_data['keys']);
                 $callback = $route_data['callback'];
                 $request->params =& $data;
                 $params =& $data;
                 break;
             }
         }
     }
     array_unshift($params, $request);
     // prepend the request to the parameters
     $this->trigger_filters('before', $request);
     $this->response = new Response($callback, $params);
     $this->response->execute();
     $this->trigger_filters('after', $request);
 }