Beispiel #1
0
 /**
  * Adds a route.
  *
  * @param string|array $setting
  * @param string|null  $name
  *
  * @return Router
  */
 public function addRoute($setting, $name = null)
 {
     if (is_string($setting)) {
         $route = new Route($setting);
     } else {
         $setting = new RouteSetting($setting);
         $route = new Route($setting->pattern);
         $route->getUrlParams()->setValues($setting->defaultValues)->requireOffsets($setting->requiredParams);
         $methods = $route->getHttpMethods();
         foreach ($setting->httpMethods as $method) {
             $methods[$method] = true;
         }
     }
     if (isset($name)) {
         $this->routes[$name] = $route;
     } else {
         $this->routes[] = $route;
     }
     return $this;
 }
Beispiel #2
0
 /**
  * @test
  * @expectedException \Neat\Router\Exception\UnexpectedValueException
  */
 public function assemble_withEmptyParameter_throwsException()
 {
     $route = new Route('/date/:year/:month/:day(/:time+)');
     $route->assemble(['year' => 'year', 'month' => 'month']);
 }