protected function resolve($index)
    {
        $callback = null;

        $stack = $this->stack;

        if (isset($this->stack[$index])) {
            $item = $stack[$index];

            $next = $this->resolve($index + 1);

            $callback = function ($request) use ($item, $next) {
                return $item->process($request, $next);
            };
        }

        return new Delegate($callback);
    }