Team Ai
Apppublic

errorcode418/php

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
Fetcher.php59 linesDownload Raw Back to Util
1<?php2/**3 * ua-parser4 *5 * Copyright (c) 2011-2012 Dave Olsen, http://dmolsen.com6 *7 * Released under the MIT license8 */9namespace UAParser\Util;10 11use Composer\CaBundle\CaBundle;12use UAParser\Exception\FetcherException;13 14class Fetcher15{16    private $resourceUri = 'https://raw.githubusercontent.com/ua-parser/uap-core/master/regexes.yaml';17 18    /** @var resource */19    private $streamContext;20 21    public function __construct($streamContext = null)22    {23        if (is_resource($streamContext) && get_resource_type($streamContext) === 'stream-context') {24            $this->streamContext = $streamContext;25        } else {26            $this->streamContext = stream_context_create(27                array(28                    'ssl' => array(29                        'verify_peer'            => true,30                        'verify_depth'           => 10,31                        'cafile'                 => CaBundle::getSystemCaRootBundlePath(),32                        static::getPeerNameKey() => 'www.github.com',33                        'disable_compression'    => true,34                    )35                )36            );37        }38    }39 40    public function fetch()41    {42        $level = error_reporting(0);43        $result = file_get_contents($this->resourceUri, null, $this->streamContext);44        error_reporting($level);45 46        if ($result === false) {47            $error = error_get_last();48            throw FetcherException::httpError($this->resourceUri, $error['message']);49        }50 51        return $result;52    }53 54    public static function getPeerNameKey()55    {56        return version_compare(PHP_VERSION, '5.6') === 1 ? 'peer_name' : 'CN_match';57    }58}59