@param \SplFileInfo $file
@param string       $useragent
@param string       $fallback

@return string
483208
public function parseFile(\SplFileInfo $file, string $useragent, string $fallback): string
    {
        try {
            $factories = $this->jsonParser->decode(
                file_get_contents($file->getPathname()),
                true
            );

            $mode  = $factories['generic'] ?? $fallback;
            $rules = $factories['rules'] ?? [];
        } catch (DecodeErrorException | \RuntimeException $e) {
            $this->logger->error($e);

            $mode  = $fallback;
            $rules = [];
        }

        foreach (array_keys($rules) as $rule) {
            if (preg_match($rule, $useragent)) {
                $mode = $rules[$rule];
                break;
            }
        }

        return $mode;
    }
822937
public function load(string $company, string $key, string $useragent = ''): array
    {
        $loaderFactory = $this->loaderFactory;

        /** @var \BrowserDetector\Loader\DeviceLoader $loader */
        $loader = $loaderFactory($company);

        return $loader->load($key, $useragent);
    }
982262
private function getFilenameFromFile(SplFileInfo $file) : string
    {
        return substr($file->getRelativePathname(), 0, -(strlen($this->fileExtension) + 1));
    }
1070192
private function convertResource(Resource $resource, \SplFileInfo $file)
    {
        return new Resource(
            array_merge(
                $resource->getMetadata(),
                [
                    'file' => $file->getRealpath(),
                ]
            ),
            $resource->getMetadata('type')
        );
    }
139057
public function parse(string $useragent): array
    {
        $mode = $this->fileParser->parseFile(
            new \SplFileInfo(self::GENERIC_FILE),
            $useragent,
            'unknown'
        );

        $key = $this->fileParser->parseFile(
            new \SplFileInfo(sprintf(self::SPECIFIC_FILE, $mode)),
            $useragent,
            'unknown'
        );

        return $this->load($key, $useragent);
    }
1064300
public function normalize(string $userAgent): string
    {
        $normalizedUserAgent = $userAgent;

        foreach ($this->normalizers as $normalizer) {
            $normalizedUserAgent = $normalizer->normalize($normalizedUserAgent);
        }

        return $normalizedUserAgent;
    }
817530
private function extractId(SplFileInfo $file, array $arguments): ?string
    {
        if (!empty($arguments)) {
            $idNode = $arguments[self::ID_ARG];

            if (!($idNode instanceof Node\StringLiteral)) {
                $position = $idNode->getLocation()->getStart();

                $this->logger->error(sprintf(
                    'Could not extract id, expected string literal but got %s (in %s on line %d column %d).',
                    $idNode->getType(),
                    $file->getRealPath(),
                    $position->getLine(),
                    $position->getColumn()
                ));
            }

            return $idNode->getValue();
        }

        return null;
    }
1070507
public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue)
    {
        if ($file->getExtension() !== 'js') {
            return;
        }

        $process = new Process('node ' . $this->translationDumperPath . ' ' . escapeshellarg($file));
        $process->run();

        $result = json_decode($process->getOutput());

        if ($result && $result->translationsFound) {
            foreach ($result->translationsFound as $translation) {
                $message = new Message($translation->key, $translation->domain);
                $message->addSource(new FileSource($file->getPathname()));
                $catalogue->add($message);
            }
        }
    }
1126522
public static function getWindowsPhoneDesktopVersion($userAgent)
    {
        if (preg_match('|Windows NT (\d+\.\d+)|', $userAgent, $matches)) {
            if (strpos($matches[1], '10.0') !== false) {
                return '10.0';
            } elseif (strpos($matches[1], '6.3') !== false || strpos($matches[1], '8.1') !== false) {
                return '8.1';
            } else {
                return '8.0';
            }
        }

        return null;
    }
24716
protected function commonCurlParams($url,$userAgent)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_PORT, 443);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        if (!is_null($this->config['cabundle_file'])) {
            curl_setopt($ch, CURLOPT_CAINFO, $this->config['cabundle_file']);
        }

        if (!empty($userAgent))
            curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);

        if ($this->config['proxy_host'] != null && $this->config['proxy_port'] != -1) {
            curl_setopt($ch, CURLOPT_PROXY, $this->config['proxy_host'] . ':' . $this->config['proxy_port']);
        }

        if ($this->config['proxy_username'] != null && $this->config['proxy_password'] != null) {
            curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->config['proxy_username'] . ':' . $this->config['proxy_password']);
        }

        return $ch;
    }
197779
public function filter(SplFileInfo $file)
    {
        try {
            $class = $this->getClassName($file->getPathname());
        } catch (Exception $e){
            return false;
        }

        $usedtraits = class_uses($class, $this->useautoload);

        foreach ($this->instances as $instance) {
            if (in_array($instance, $usedtraits)) {
                return true;
            }
        }

        return false;
    }
881562
protected function getFileName(SplFileInfo $file = null)
    {
        $file = $file ?: $this->file;

        return str_replace(['.blade.php', '.php', '.md'], '', $file->getBasename());
    }
939177
public function getUserAgent(): string
    {
        $userAgent = 'Swoft/' . App::version();
        $userAgent .= ' Swoft/' . SWOOLE_VERSION;
        $userAgent .= ' PHP/' . PHP_VERSION;
        return $userAgent;
    }
1267120
public function setDefaults($userAgent = null)
    {
        $this->setDefaultHeaders();
        $this->setDefaultOptions();

        if (!empty($userAgent)) {
            $this->setUserAgent($userAgent);
        } else {
            $this->setUserAgent('chrome');
        }
    }
58586
public static function generateSelfLink($path, $userAgentEnabled)
    {
        if ($start = strpos($path, '/pages/')) {
            $path = substr($path, $start + 7);
            if ($userAgentEnabled && (substr( $path, 0, 3 ) === "new" || substr( $path, 0, 3 ) === "old")) {
                $path = substr($path, 4);
            }
        } elseif ($start = strpos($path, '/templates/')) {
            $path = substr($path, $start + 11);
        }

        return '/'.trim(str_replace(['.html.twig', 'index'], '', $path), '/');
    }
906965
public function detectVersion(string $useragent, array $searches = [], string $default = '0'): VersionInterface
    {
        $modifiers = [
            ['\/', ''],
            ['\(', '\)'],
            [' ', ';'],
            [' ', ''],
            ['', ''],
            [' \(', ';'],
        ];

        $version = $default;

        if (false !== mb_strpos($useragent, '%')) {
            $useragent = urldecode($useragent);
        }

        foreach ($searches as $search) {
            if (!is_string($search)) {
                continue;
            }

            if (false !== mb_strpos($search, '%')) {
                $search = urldecode($search);
            }

            foreach ($modifiers as $modifier) {
                $compareString = '/' . $search . $modifier[0] . '(\d+[\d._\-+ abcdehlprstv]*)' . $modifier[1] . '/i';
                $matches       = [];
                $doMatch       = preg_match($compareString, $useragent, $matches);

                if ($doMatch) {
                    $version = mb_strtolower(str_replace('_', '.', $matches[1]));

                    break 2;
                }
            }
        }

        return $this->set($version);
    }
177634
protected function parseXml(SplFileInfo $file)
    {
        $dom = XmlUtils::loadFile($file, realpath(dirname(__DIR__) . DS . 'Schema' . DS . 'smarty_filter.xsd'));
        /** @var \Symfony\Component\DependencyInjection\SimpleXMLElement $xml */
        $xml = simplexml_import_dom($dom, '\\Symfony\\Component\\DependencyInjection\\SimpleXMLElement');

        $parsedConfig = [];
        /** @var \Symfony\Component\DependencyInjection\SimpleXMLElement $smartyFilterDefinition */
        foreach ($xml->smartyfilter as $smartyFilterDefinition) {
            $descriptive = [];
            /** @var \Symfony\Component\DependencyInjection\SimpleXMLElement $descriptiveDefinition */
            foreach ($smartyFilterDefinition->descriptive as $descriptiveDefinition) {
                $descriptive[] = [
                    'locale' => $descriptiveDefinition->getAttributeAsPhp('locale'),
                    'title' => (string)$descriptiveDefinition->title,
                    'description' => (string)$descriptiveDefinition->description,
                    'type' => (string)$descriptiveDefinition->type
                ];
            }

            $parsedConfig['smarty_filter'][] = [
                'code' => $smartyFilterDefinition->getAttributeAsPhp('code'),
                'descriptive' => $descriptive
            ];
        }


        return $parsedConfig;
    }