Beispiel #1
0
 /**
  * Searches for a route matching the provided request.
  */
 function getRoute(\assegai\Request $request)
 {
     $path = $request->getRoute();
     $call = false;
     // This will store the controller and method to call
     $matches = array();
     // And this the extracted parameters.
     // First we search for specific method routes.
     $method_routes = preg_grep('%^' . $request->getMethod() . ':%i', array_keys($this->routes));
     foreach ($method_routes as $route) {
         $method = $request->getMethod() . ':';
         $clean_route = substr($route, strlen($method));
         if (preg_match('%^' . $clean_route . '/?$%i', $path, $matches)) {
             $call = $this->routes[$route];
             break;
         }
     }
     // Do we need to try generic routes?
     if (!$call) {
         foreach ($this->routes as $regex => $proto) {
             if (preg_match('%^' . $regex . '/?$%i', $path, $matches)) {
                 $call = $proto;
                 break;
             }
         }
     }
     // If we don't have a call at this point, that's a 404.
     if (!$call) {
         throw new \assegai\exceptions\NoRouteException(sprintf('URL %s not found.', $request->getWholeRoute()), $this->routes);
     }
     // Cleaning up the matches. The first one is always the current URL.
     $params = array_slice($matches, 1);
     if (is_array($call)) {
         $params = array_merge(array($call[1]), $params);
         $call = $call[0];
     }
     $call->setParams($params);
     return $call;
 }
Beispiel #2
0
 public function logout(\assegai\Request $request)
 {
     $request->setSession('auth_username', null);
 }