public function dispatch(Context $context) { $context->withBundle($this); if (is_null($this->stack)) { $this->stack = [$this]; if ($this->middlewares) { $len = count($this->middlewares); for ($i = $len - 1; $i >= 0; $i--) { $next = $this->stack[0]; $handler = $this->middlewares[$i]->getHandler(); array_unshift($this->stack, function (Context $context) use($next, $handler) { return call_user_func($handler, $context, $next); }); } } } $path = $context->getPathname() ?: '/'; $bundle = $this->getBundleFor($path); if (is_null($bundle)) { $routeInfo = $this->getDispatcher()->dispatch($context->getMethod(), $path); $context['routeInfo'] = $routeInfo; } else { $context['routeBundle'] = $bundle; } return $this->stack[0]($context); }