protected function convertMiddlewareToPipelineStages(array $middleware) : array
    {
        $stages = [];

        foreach ($middleware as $singleMiddleware) {
            if ($singleMiddleware instanceof MiddlewareParameters) {
                /** @var MiddlewareParameters $singleMiddleware */
                /** @var ParameterizedMiddleware $tempMiddleware */
                $tempMiddleware = $this->container->resolve($singleMiddleware->getMiddlewareClassName());
                $tempMiddleware->setParameters($singleMiddleware->getParameters());
                $singleMiddleware = $tempMiddleware;
            } elseif (is_string($singleMiddleware)) {
                $singleMiddleware = $this->container->resolve($singleMiddleware);
            }

            $stages[] = $singleMiddleware;
        }

        return $stages;
    }