public function getBrowser(string $userAgent = null) : \stdClass
    {
        if (null === $this->cache->getVersion()) {
            // there is no active/warm cache available
            throw new Exception('there is no active cache available, please use the BrowscapUpdater and run the update command');
        }

        // Automatically detect the useragent
        if (! is_string($userAgent)) {
            $support = new Helper\Support($_SERVER);
            $userAgent = $support->getUserAgent();
        }

        try {
            // try to get browser data
            $formatter = $this->getParser()->getBrowser($userAgent);
        } catch (\UnexpectedValueException $e) {
            $this->logger->error(sprintf('could not parse useragent "%s"', $userAgent));
            $formatter = null;
        }

        // if return is still NULL, updates are disabled... in this
        // case we return an empty formatter instance
        if (null === $formatter) {
            $formatter = $this->formatter;
        }

        return $formatter->getData();
    }
public function getBrowser(string $userAgent = null) : \stdClass
    {
        if (null === $this->cache->getVersion()) {
            // there is no active/warm cache available
            throw new Exception('there is no active cache available, please use the BrowscapUpdater and run the update command');
        }

        // Automatically detect the useragent
        if (! is_string($userAgent)) {
            $support = new Helper\Support($_SERVER);
            $userAgent = $support->getUserAgent();
        }

        try {
            // try to get browser data
            $formatter = $this->getParser()->getBrowser($userAgent);
        } catch (\UnexpectedValueException $e) {
            $this->logger->error(sprintf('could not parse useragent "%s"', $userAgent));
            $formatter = null;
        }

        // if return is still NULL, updates are disabled... in this
        // case we return an empty formatter instance
        if (null === $formatter) {
            $formatter = $this->formatter;
        }

        return $formatter->getData();
    }
public function getBrowser ( string $ userAgent = null ) : \ stdClass { if ( null === $ this -> cache -> getVersion ( ) ) { // there is no active/warm cache available throw new Exception ( 'there is no active cache available, please use the BrowscapUpdater and run the update command' ) ; } // Automatically detect the useragent if ( ! is_string ( $ userAgent ) ) { $ support = new Helper \ Support ( $ _SERVER ) ; $ userAgent = $ support -> getUserAgent ( ) ; } try { // try to get browser data $ formatter = $ this -> getParser ( ) -> getBrowser ( $ userAgent ) ; } catch ( \ UnexpectedValueException $ e ) { $ this -> logger -> error ( sprintf ( 'could not parse useragent "%s"' , $ userAgent ) ) ; $ formatter = null ; } // if return is still NULL, updates are disabled... in this // case we return an empty formatter instance if ( null === $ formatter ) { $ formatter = $ this -> formatter ; } return $ formatter -> getData ( ) ; }
parses the given user agent to get the information about the browser

if no user agent is given, it uses {@see \BrowscapPHP\Helper\Support} to get it

@param string $userAgent the user agent string

@throws \BrowscapPHP\Exception

@return \stdClass              the object containing the browsers details.
parses the given user agent to get the information about the browser