private function resolveControllerParameters(
        array $reflectionParameters,
        array $pathVars,
        CompiledRoute $route,
        bool $acceptObjectParameters
    ) : array {
        $resolvedParameters = [];

        // Match the route variables to the method parameters
        foreach ($reflectionParameters as $parameter) {
            if ($acceptObjectParameters && $parameter->getClass() !== null) {
                $className = $parameter->getClass()->getName();
                $resolvedParameters[$parameter->getPosition()] = $this->dependencyResolver->resolve($className);
            } elseif (isset($pathVars[$parameter->getName()])) {
                // There is a value set in the route
                $resolvedParameters[$parameter->getPosition()] = $pathVars[$parameter->getName()];
            } elseif (($defaultValue = $route->getDefaultValue($parameter->getName())) !== null) {
                // There was a default value set in the route
                $resolvedParameters[$parameter->getPosition()] = $defaultValue;
            } elseif (!$parameter->isDefaultValueAvailable()) {
                // There is no value/default value for this variable
                throw new RouteException(
                    "No value set for parameter {$parameter->getName()}"
                );
            }
        }

        return $resolvedParameters;
    }