public function generate($type, $object, $absolute = false, array $extraParams = array())
    {
        if ( ! is_object($object)) {
            throw new \InvalidArgumentException(sprintf('$object must be an object, but got "%s".', gettype($object)));
        }

        /** @var $metadata ClassMetadata */
        $metadata = $this->metadataFactory->getMetadataForClass(get_class($object));
        if (null === $metadata) {
            throw new \RuntimeException(sprintf('There were no object routes defined for class "%s".', get_class($object)));
        }

        if ( ! isset($metadata->routes[$type])) {
            throw new \RuntimeException(sprintf(
                'The object of class "%s" has no route with type "%s". Available types: %s',
                get_class($object),
                $type,
                implode(', ', array_keys($metadata->routes))
            ));
        }

        $route = $metadata->routes[$type];

        $params = $extraParams;
        foreach ($route['params'] as $k => $path) {
            $params[$k] = $this->accessor->getValue($object, $path);
        }

        return $this->router->generate($route['name'], $params, $absolute);
    }