<commit_before><?php

namespace Grid\Embed\Model\Parser\Oembed\Provider;

use Zend\Dom\Query;
use Grid\Embed\Model\Parser\Oembed;
use Grid\Embed\Model\Parser\Oembed\ProviderAbstract;

/**
 * Default Oembed provider adapter
 * Implements Oembed discovery mode
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class DefaultDiscovery extends ProviderAbstract
{

    /**
     * Stores readed provider API endpint URL with request URL
     *
     * @var string
     */
    private $_feedUrl    = null;

    /**
     * Stores provider response data format
     *
     * @var string json|xml
     */
    private $_feedFormat = null;

    /**
     * @see \Embed\Model\Parser\Oembed\ProviderAbstract::getFeedUrl()
     *
     * @param string $contentUrl
     * @return string|false
     */
    public function getFeedUrl( $contentUrl )
    {
        if ( is_null( $this->_feedUrl ) )
        {
            $this->discover( $contentUrl );
        }

        return $this->_feedUrl;
    }

    /**
     * @see \Embed\Model\Parser\Oembed\ProviderAbstract::getFeedFormat()
     *
     * @return string json|xml
     */
    public function getFeedFormat()
    {
        return $this->_feedFormat;
    }

    /**
     * Tries discover the given URL and set $_feedUrl and $_feedFormat
     * returns FALSE if no oembed data
     *
     * @param string|false $url
     */
    private function discover( $url )
    {
        static $paths = array(
            Oembed::FEED_FORMAT_JSON => '//link[@href][@type=\'application/json+oembed\']',
            Oembed::FEED_FORMAT_XML  => '//link[@href][@type=\'text/xml+oembed\']',
        );

        $this->_feedUrl = false;

        try
        {
            $httpClient     = clone $this->getServiceLocator()
                                         ->get( 'Zend\Http\Client' );
            $httpResponse   = $httpClient->setUri( $url )
                                         ->send();

            if ( $httpResponse && $httpResponse->isSuccess())
            {
                $query = new Query( $httpResponse->getBody() );

                foreach ( $paths as $format => $path )
                {
                    foreach ( $query->queryXpath( $path ) as $node )
                    {
                        $this->_feedFormat  = $format;<commit_msg>Zend\Http\Client is not shared by default (from now)<commit_after><?php

namespace Grid\Embed\Model\Parser\Oembed\Provider;

use Zend\Dom\Query;
use Grid\Embed\Model\Parser\Oembed;
use Grid\Embed\Model\Parser\Oembed\ProviderAbstract;

/**
 * Default Oembed provider adapter
 * Implements Oembed discovery mode
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class DefaultDiscovery extends ProviderAbstract
{

    /**
     * Stores readed provider API endpint URL with request URL
     *
     * @var string
     */
    private $_feedUrl    = null;

    /**
     * Stores provider response data format
     *
     * @var string json|xml
     */
    private $_feedFormat = null;

    /**
     * @see \Embed\Model\Parser\Oembed\ProviderAbstract::getFeedUrl()
     *
     * @param string $contentUrl
     * @return string|false
     */
    public function getFeedUrl( $contentUrl )
    {
        if ( is_null( $this->_feedUrl ) )
        {
            $this->discover( $contentUrl );
        }

        return $this->_feedUrl;
    }

    /**
     * @see \Embed\Model\Parser\Oembed\ProviderAbstract::getFeedFormat()
     *
     * @return string json|xml
     */
    public function getFeedFormat()
    {
        return $this->_feedFormat;
    }

    /**
     * Tries discover the given URL and set $_feedUrl and $_feedFormat
     * returns FALSE if no oembed data
     *
     * @param string|false $url
     */
    private function discover( $url )
    {
        static $paths = array(
            Oembed::FEED_FORMAT_JSON => '//link[@href][@type=\'application/json+oembed\']',
            Oembed::FEED_FORMAT_XML  => '//link[@href][@type=\'text/xml+oembed\']',
        );

        $this->_feedUrl = false;

        try
        {
            $httpClient     = $this->getServiceLocator()
                                   ->get( 'Zend\Http\Client' );
            $httpResponse   = $httpClient->setUri( $url )
                                         ->send();

            if ( $httpResponse && $httpResponse->isSuccess())
            {
                $query = new Query( $httpResponse->getBody() );

                foreach ( $paths as $format => $path )
                {
                    foreach ( $query->queryXpath( $path ) as $node )
                    {
                        $this->_feedFormat  = $format;
{'fraction_non_alphanumeric': 0.1295616497516735, 'fraction_numerical': 0.0, 'mean_word_length': 1.7686790197250448, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3108817', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1301, 'n_words': 287}