Beispiel #1
0
 /**
  * @param Route $route
  */
 public function addRoute(Route $route)
 {
     $name = $route->getName();
     $path = $route->getPath();
     $options = $route->getOptions();
     $options = array_replace_recursive($options, ['route' => $path, 'defaults' => ['middleware' => $route->getMiddleware()]]);
     $allowedMethods = $route->getAllowedMethods();
     if (Route::HTTP_METHOD_ANY === $allowedMethods) {
         $this->zf2Router->addRoute($name, ['type' => 'segment', 'options' => $options]);
         $this->routeNameMap[$name] = $name;
         return;
     }
     // Remove the middleware from the segment route in favor of method route
     unset($options['defaults']['middleware']);
     if (empty($options['defaults'])) {
         unset($options['defaults']);
     }
     $httpMethodRouteName = implode(':', $allowedMethods);
     $httpMethodRoute = $this->createHttpMethodRoute($route);
     $methodNotAllowedRoute = $this->createMethodNotAllowedRoute($path);
     $spec = ['type' => 'segment', 'options' => $options, 'may_terminate' => false, 'child_routes' => [$httpMethodRouteName => $httpMethodRoute, self::METHOD_NOT_ALLOWED_ROUTE => $methodNotAllowedRoute]];
     if (array_key_exists($path, $this->allowedMethodsByPath)) {
         $allowedMethods = array_merge($this->allowedMethodsByPath[$path], $allowedMethods);
         // Remove the method not allowed route as it is already present for the path
         unset($spec['child_routes'][self::METHOD_NOT_ALLOWED_ROUTE]);
     }
     $this->zf2Router->addRoute($name, $spec);
     $this->allowedMethodsByPath[$path] = $allowedMethods;
     $this->routeNameMap[$name] = sprintf('%s/%s', $name, $httpMethodRouteName);
 }
Beispiel #2
0
 /**
  * @param Route $route
  */
 public function addRoute(Route $route)
 {
     $path = $route->getPath();
     $options = $route->getOptions() ?: [];
     $options = array_replace_recursive($options, ['route' => $route->getPath(), 'defaults' => ['middleware' => $route->getMiddleware()]]);
     $spec = ['type' => 'segment', 'options' => $options];
     $this->zf2Router->addRoute($path, $spec);
     $this->routes[$path] = $route;
 }
 public function testCanSpecifyAuraRouteValuesViaRouteOptions()
 {
     $route = new Route('/foo', 'foo', ['GET']);
     $route->setOptions(['values' => ['foo' => 'bar']]);
     $this->auraRoute->setServer(['REQUEST_METHOD' => 'GET'])->shouldBeCalled();
     $this->auraRoute->addValues($route->getOptions()['values'])->shouldBeCalled();
     $this->auraRouter->add('/foo^GET', '/foo', 'foo')->willReturn($this->auraRoute->reveal());
     $router = $this->getRouter();
     $router->addRoute($route);
 }
Beispiel #4
0
 /**
  * Add a route to the underlying router.
  *
  * Adds the route to the Aura.Router, using the path as the name, and a
  * middleware value equivalent to the middleware in the Route instance.
  *
  * If HTTP methods are defined (and not the wildcard), they are imploded
  * with a pipe symbol and added as server REQUEST_METHOD criteria.
  *
  * If tokens or values are present in the options array, they are also
  * added to the router.
  *
  * @param Route $route
  */
 public function addRoute(Route $route)
 {
     $auraRoute = $this->router->add($route->getPath(), $route->getPath(), $route->getMiddleware());
     $httpMethods = $route->getAllowedMethods();
     if (is_array($httpMethods)) {
         $auraRoute->setServer(['REQUEST_METHOD' => implode('|', $httpMethods)]);
     }
     foreach ($route->getOptions() as $key => $value) {
         switch ($key) {
             case 'tokens':
                 $auraRoute->addTokens($value);
                 break;
             case 'values':
                 $auraRoute->addValues($value);
                 break;
         }
     }
 }
 /**
  * @param Route $route
  */
 public function addRoute(Route $route)
 {
     $slimRoute = new \Slim\Route($route->getPath(), [$this, 'dummyCallable']);
     $slimRoute->setName($route->getName());
     $allowedMethods = $route->getAllowedMethods();
     $slimRoute->via($allowedMethods === Route::HTTP_METHOD_ANY ? 'ANY' : $allowedMethods);
     // Process options
     $options = $route->getOptions();
     if (isset($options['conditions']) && is_array($options['conditions'])) {
         $slimRoute->setConditions($options['conditions']);
     }
     // The middleware is merged with the rest of the route params
     $params = ['middleware' => $route->getMiddleware()];
     if (isset($options['defaults']) && is_array($options['defaults'])) {
         $params = array_merge($options['defaults'], $params);
     }
     $slimRoute->setParams($params);
     $this->router->map($slimRoute);
 }
Beispiel #6
0
 /**
  * Add a route to the underlying router.
  *
  * Adds the route to the Aura.Router, using the path as the name, and a
  * middleware value equivalent to the middleware in the Route instance.
  *
  * If HTTP methods are defined (and not the wildcard), they are imploded
  * with a pipe symbol and added as server REQUEST_METHOD criteria.
  *
  * If tokens or values are present in the options array, they are also
  * added to the router.
  *
  * @param Route $route
  */
 public function addRoute(Route $route)
 {
     $path = $route->getPath();
     $auraRoute = $this->router->add($route->getName(), $path, $route->getMiddleware());
     foreach ($route->getOptions() as $key => $value) {
         switch ($key) {
             case 'tokens':
                 $auraRoute->addTokens($value);
                 break;
             case 'values':
                 $auraRoute->addValues($value);
                 break;
         }
     }
     $allowedMethods = $route->getAllowedMethods();
     if (Route::HTTP_METHOD_ANY === $allowedMethods) {
         return;
     }
     $auraRoute->setServer(['REQUEST_METHOD' => implode('|', $allowedMethods)]);
     if (array_key_exists($path, $this->routes)) {
         $allowedMethods = array_merge($this->routes[$path], $allowedMethods);
     }
     $this->routes[$path] = $allowedMethods;
 }
Beispiel #7
0
 public function testRouteOptionsAreEmptyByDefault()
 {
     $route = new Route('/foo', $this->noopMiddleware);
     $this->assertSame([], $route->getOptions());
 }
Beispiel #8
0
 /**
  * Injects route into the underlying router implemetation.
  *
  * @param Route $route
  */
 protected function injectRoute(Route $route)
 {
     $pathParser = new Segment('/', $route->getPath(), []);
     $options = $route->getOptions();
     $defaults = isset($options['defaults']) ? $options['defaults'] : [];
     $methods = Route::HTTP_METHOD_ANY === $route->getAllowedMethods() ? null : $route->getAllowedMethods();
     $this->routeCollection->add($route->getName(), new Generic($pathParser, null, $methods, null, null, $defaults));
 }