src/Extractor/HttpClient.php
private function getUserAgent($url, $httpHeader = [])
    {
        $ua = $this->config['ua_browser'];

        if (!empty($httpHeader['user-agent'])) {
            $this->logger->info('Found user-agent "{user-agent}" for url "{url}" from site config', ['user-agent' => $httpHeader['user-agent'], 'url' => $url]);

            return $httpHeader['user-agent'];
        }

        $host = parse_url($url, PHP_URL_HOST);

        if ('www.' === strtolower(substr($host, 0, 4))) {
            $host = substr($host, 4);
        }

        $try = [$host];
        $split = explode('.', $host);

        if (\count($split) > 1) {
            // remove first subdomain
            array_shift($split);
            $try[] = '.' . implode('.', $split);
        }

        foreach ($try as $h) {
            if (isset($this->config['user_agents'][$h])) {
                $this->logger->info('Found user-agent "{user-agent}" for url "{url}" from config', ['user-agent' => $this->config['user_agents'][$h], 'url' => $url]);

                return $this->config['user_agents'][$h];
            }
        }

        $this->logger->info('Use default user-agent "{user-agent}" for url "{url}"', ['user-agent' => $ua, 'url' => $url]);

        return $ua;
    }
private function getUserAgent($url, $httpHeader = [])
    {
        $ua = $this->config['ua_browser'];

        if (!empty($httpHeader['user-agent'])) {
            $this->logger->info('Found user-agent "{user-agent}" for url "{url}" from site config', ['user-agent' => $httpHeader['user-agent'], 'url' => $url]);

            return $httpHeader['user-agent'];
        }

        $host = parse_url($url, PHP_URL_HOST);

        if ('www.' === strtolower(substr($host, 0, 4))) {
            $host = substr($host, 4);
        }

        $try = [$host];
        $split = explode('.', $host);

        if (\count($split) > 1) {
            // remove first subdomain
            array_shift($split);
            $try[] = '.' . implode('.', $split);
        }

        foreach ($try as $h) {
            if (isset($this->config['user_agents'][$h])) {
                $this->logger->info('Found user-agent "{user-agent}" for url "{url}" from config', ['user-agent' => $this->config['user_agents'][$h], 'url' => $url]);

                return $this->config['user_agents'][$h];
            }
        }

        $this->logger->info('Use default user-agent "{user-agent}" for url "{url}"', ['user-agent' => $ua, 'url' => $url]);

        return $ua;
    }
private function getUserAgent ( $ url , $ httpHeader = [ ] ) { $ ua = $ this -> config [ 'ua_browser' ] ; if ( ! empty ( $ httpHeader [ 'user-agent' ] ) ) { $ this -> logger -> info ( 'Found user-agent "{user-agent}" for url "{url}" from site config' , [ 'user-agent' => $ httpHeader [ 'user-agent' ] , 'url' => $ url ] ) ; return $ httpHeader [ 'user-agent' ] ; } $ host = parse_url ( $ url , PHP_URL_HOST ) ; if ( 'www.' === strtolower ( substr ( $ host , 0 , 4 ) ) ) { $ host = substr ( $ host , 4 ) ; } $ try = [ $ host ] ; $ split = explode ( '.' , $ host ) ; if ( \ count ( $ split ) > 1 ) { // remove first subdomain array_shift ( $ split ) ; $ try [ ] = '.' . implode ( '.' , $ split ) ; } foreach ( $ try as $ h ) { if ( isset ( $ this -> config [ 'user_agents' ] [ $ h ] ) ) { $ this -> logger -> info ( 'Found user-agent "{user-agent}" for url "{url}" from config' , [ 'user-agent' => $ this -> config [ 'user_agents' ] [ $ h ] , 'url' => $ url ] ) ; return $ this -> config [ 'user_agents' ] [ $ h ] ; } } $ this -> logger -> info ( 'Use default user-agent "{user-agent}" for url "{url}"' , [ 'user-agent' => $ ua , 'url' => $ url ] ) ; return $ ua ; }
Find a UserAgent for this url.
Based on the config, it will try to find a UserAgent from an host.
Otherwise it will use the default one.

@param string $url        Absolute url
@param array  $httpHeader Custom HTTP Headers from SiteConfig

@return string
Find a UserAgent for this url . Based on the config it will try to find a UserAgent from an host . Otherwise it will use the default one .