/**
  * Inject route into the underlying router implemetation.
  *
  * @param Route $route
  */
 private function injectRoute(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->zendRouter->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->zendRouter->addRoute($name, $spec);
     $this->allowedMethodsByPath[$path] = $allowedMethods;
     $this->routeNameMap[$name] = sprintf('%s/%s', $name, $httpMethodRouteName);
 }
 public function setUp()
 {
     $router = new TreeRouteStack();
     $router->addRoute('home', LiteralRoute::factory(['route' => '/', 'defaults' => ['controller' => TestAsset\SampleController::class]]));
     $router->addRoute('sub', SegmentRoute::factory(['route' => '/foo/:param', 'defaults' => ['param' => 1]]));
     $router->addRoute('ctl', SegmentRoute::factory(['route' => '/ctl/:controller', 'defaults' => ['__NAMESPACE__' => 'ZendTest\\Mvc\\Plugin\\Prg\\TestAsset', 'controller' => 'sample']]));
     $this->controller = new TestAsset\SampleController();
     $this->request = new Request();
     $this->event = new MvcEvent();
     $this->routeMatch = new RouteMatch(['controller' => 'controller-sample', 'action' => 'postPage']);
     $this->event->setRequest($this->request);
     $this->event->setRouteMatch($this->routeMatch);
     $this->event->setRouter($router);
     $this->controller->setEvent($this->event);
     $this->plugin = new PostRedirectGet();
     $this->plugin->setController($this->controller);
 }