Imbo\Http\Request\Request::setRoute PHP Method

setRoute() public method

Set the route
public setRoute ( Imbo\Router\Route $route ) : self
$route Imbo\Router\Route The current route
return self
    public function setRoute(Route $route)
    {
        $this->route = $route;
        return $this;
    }

Usage Example

Example #1
0
File: Router.php Project: imbo/imbo
 /**
  * Route the current request
  *
  * @param Request $request The current request
  */
 public function route(Request $request)
 {
     $httpMethod = $request->getMethod();
     if ($httpMethod === 'BREW') {
         throw new RuntimeException('I\'m a teapot!', 418);
     }
     if (!isset(self::$supportedHttpMethods[$httpMethod])) {
         throw new RuntimeException('Unsupported HTTP method: ' . $httpMethod, 501);
     }
     $path = $request->getPathInfo();
     $matches = [];
     foreach ($this->routes as $resourceName => $route) {
         if (preg_match($route, $path, $matches)) {
             break;
         }
     }
     // Path matched no route
     if (!$matches) {
         throw new RuntimeException('Not Found', 404);
     }
     // Create and populate a route instance that we want to inject into the request
     $route = new Route();
     $route->setName($resourceName);
     // Inject all matches into the route as parameters
     foreach ($matches as $key => $value) {
         if (is_string($key)) {
             $route->set($key, $value);
         }
     }
     // Store the route in the request
     $request->setRoute($route);
 }
All Usage Examples Of Imbo\Http\Request\Request::setRoute