public function guessTemplateNames($controller, Request $request)
    {
        if (is_object($controller) && method_exists($controller, '__invoke')) {
            $controller = [$controller, '__invoke'];
        } elseif (!is_array($controller)) {
            throw new \InvalidArgumentException(sprintf('First argument of %s must be an array callable or an object defining the magic method __invoke. "%s" given.', __METHOD__, gettype($controller)));
        }

        if (!is_string($controller[0])) {
            $controller[0] = class_exists('Doctrine\Common\Util\ClassUtils')
                ? ClassUtils::getClass($controller[0])
                : get_class($controller[0]);
        }

        $reflClass = new \ReflectionClass($controller[0]);
        $templates = [];

        do {
            $controller[0] = $reflClass->getName();

            if ($template = $this->guessTemplateName($controller, $request)) {
                $templates[] = $template;
            }

            $reflClass = $reflClass->getParentClass();
        } while ($reflClass);

        return $templates;
    }