public function getController(Request $request, array $matched)
    {
        if (null !== $request->attributes->get('_controller')) {
            return $this->createController($request->attributes->get('_controller'));
        }

        if ( ! $controller = $matched['_controller']) {
            throw new \InvalidArgumentException('Unable to look for controller as the "_controller" parameter is missing');
        }

        $callable = $this->createController($controller);

        if ( ! is_callable($callable)) {
            throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', $controller, $request));
        }

        return $callable;
    }