public function consume($url, Provider $provider = null, $format = self::FORMAT_DEFAULT)
    {
        if ($this->requestParameters instanceof RequestParameters) {
            $cacheKey = sha1($url . json_encode($this->requestParameters->toArray()));
        } else {
            $cacheKey = sha1($url);
        }

        // Check if the resource is cached
        if ($this->resourceCache->has($cacheKey)) {
            return $this->resourceCache->get($cacheKey);
        }

        try {
            // Try to find a provider matching the supplied URL if no one has been supplied.
            if (!$provider) {
                $provider = $this->findProviderForUrl($url);
            }

            if ($provider instanceof Provider) {
                // If a provider was supplied or we found one, store the endpoint URL.
                $endPoint = $provider->getEndpoint();
            } else {
                // If no provider was found, try to discover the endpoint URL.
                $discover = new Discoverer();
                $endPoint = $discover->getEndpointForUrl($url);
            }

            $requestUrl = $this->buildOEmbedRequestUrl($url, $endPoint, $format);
            $content = $this->browser->getContent($requestUrl);

            $methodName = 'process' . ucfirst(strtolower($format)) . 'Response';

            $resource = $this->$methodName($content);

            // Save the resource in cache
            $this->resourceCache->set($cacheKey, $resource);
        } catch (Exception $exception) {
            $this->systemLogger->logException($exception);
            $resource = null;
        }

        return $this->postProcessResource($resource);
    }
public function consume($url, Provider $provider = null, $format = self::FORMAT_DEFAULT)
    {
        if ($this->requestParameters instanceof RequestParameters) {
            $cacheKey = sha1($url . json_encode($this->requestParameters->toArray()));
        } else {
            $cacheKey = sha1($url);
        }

        // Check if the resource is cached
        if ($this->resourceCache->has($cacheKey)) {
            return $this->resourceCache->get($cacheKey);
        }

        try {
            // Try to find a provider matching the supplied URL if no one has been supplied.
            if (!$provider) {
                $provider = $this->findProviderForUrl($url);
            }

            if ($provider instanceof Provider) {
                // If a provider was supplied or we found one, store the endpoint URL.
                $endPoint = $provider->getEndpoint();
            } else {
                // If no provider was found, try to discover the endpoint URL.
                $discover = new Discoverer();
                $endPoint = $discover->getEndpointForUrl($url);
            }

            $requestUrl = $this->buildOEmbedRequestUrl($url, $endPoint, $format);
            $content = $this->browser->getContent($requestUrl);

            $methodName = 'process' . ucfirst(strtolower($format)) . 'Response';

            $resource = $this->$methodName($content);

            // Save the resource in cache
            $this->resourceCache->set($cacheKey, $resource);
        } catch (Exception $exception) {
            $this->systemLogger->logException($exception);
            $resource = null;
        }

        return $this->postProcessResource($resource);
    }
public function consume ( $ url , Provider $ provider = null , $ format = self :: FORMAT_DEFAULT ) { if ( $ this -> requestParameters instanceof RequestParameters ) { $ cacheKey = sha1 ( $ url . json_encode ( $ this -> requestParameters -> toArray ( ) ) ) ; } else { $ cacheKey = sha1 ( $ url ) ; } // Check if the resource is cached if ( $ this -> resourceCache -> has ( $ cacheKey ) ) { return $ this -> resourceCache -> get ( $ cacheKey ) ; } try { // Try to find a provider matching the supplied URL if no one has been supplied. if ( ! $ provider ) { $ provider = $ this -> findProviderForUrl ( $ url ) ; } if ( $ provider instanceof Provider ) { // If a provider was supplied or we found one, store the endpoint URL. $ endPoint = $ provider -> getEndpoint ( ) ; } else { // If no provider was found, try to discover the endpoint URL. $ discover = new Discoverer ( ) ; $ endPoint = $ discover -> getEndpointForUrl ( $ url ) ; } $ requestUrl = $ this -> buildOEmbedRequestUrl ( $ url , $ endPoint , $ format ) ; $ content = $ this -> browser -> getContent ( $ requestUrl ) ; $ methodName = 'process' . ucfirst ( strtolower ( $ format ) ) . 'Response' ; $ resource = $ this -> $ methodName ( $ content ) ; // Save the resource in cache $ this -> resourceCache -> set ( $ cacheKey , $ resource ) ; } catch ( Exception $ exception ) { $ this -> systemLogger -> logException ( $ exception ) ; $ resource = null ; } return $ this -> postProcessResource ( $ resource ) ; }
Consume an oEmbed resource using the specified provider if supplied
or try to discover the right one.

@param  string $url The URL of the resource to consume.
@param  Provider $provider The provider to use.
@param  string $format The format of the data to fetch.
@return AbstractResource An object representation of the oEmbed resource or NULL on error
Consume an oEmbed resource using the specified provider if supplied or try to discover the right one .