public static function parse($ua = NULL) {

        self::$ua      = $ua ? $ua : strip_tags($_SERVER["HTTP_USER_AGENT"]);
        self::$accept  = empty($_SERVER["HTTP_ACCEPT"]) ? '' : strip_tags($_SERVER["HTTP_ACCEPT"]);
        if (empty(self::$regexes)) {
            if (file_exists(__DIR__."/resources/regexes.yaml")) {
                self::$regexes = Yaml::parse(__DIR__."/resources/regexes.yaml");
            } else {
                print "<h1>Error</h1>
                    <p>Please download the regexes.yaml file before using UAParser.php.</p>
                    <p>You can type the following at the command line to download the latest version:</p>
                    <blockquote>
                    <code>%: cd /path/to/UAParser</code><br />
                    <code>%: php UAParser.php -get</code>
                    </blockquote>";
                exit;
            }
        }


        // run the regexes to match things up
        $uaRegexes = self::$regexes['user_agent_parsers'];
        foreach ($uaRegexes as $uaRegex) {
            if ($result = self::uaParser($uaRegex)) {
                $result->uaOriginal = self::$ua;
                break;
            }
        }

        // if no browser was found check to see if it can be matched at least against a device (e.g. spider, generic feature phone or generic smartphone)
        if (!$result) {
            if (($result = self::deviceParser()) && ($result->device != 'Spider')) {
                $result->isMobile       = true;
                $result->isMobileDevice = true;	
                $result->uaOriginal     = self::$ua;
            } else if (isset($result) && isset($result->device) && ($result->device == "Spider")) {
                $result->isMobile       = false;
                $result->isSpider       = true;
                $result->uaOriginal     = self::$ua;
            }
        }

        // still false?! see if it's a really dumb feature phone, if not just mark it as unknown
        if (!$result) {
            if ((strpos(self::$accept,'text/vnd.wap.wml') > 0) || (strpos(self::$accept,'application/vnd.wap.xhtml+xml') > 0) || isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {
                $result = new \stdClass();
                $result->device         = "Generic Feature Phone";
                $result->deviceFull     = "Generic Feature Phone";
                $result->isMobile       = true;
                $result->isMobileDevice = true;
                $result->uaOriginal     = self::$ua;
            } else {
                $result = new \stdClass();
                $result->device         = "Unknown";
                $result->deviceFull     = "Unknown";
                $result->isMobile       = false;
                $result->isMobileDevice = false;
                $result->isComputer     = true;
                $result->uaOriginal     = self::$ua;
            }
        }

        // log the results when testing
        if (self::$debug) {
            self::log($result);
        }

        return $result;
    }