DeviceDetector\Parser\Device\DeviceParserAbstract::parse PHP Method

parse() public method

public parse ( )
    public function parse()
    {
        $regexes = $this->getRegexes();
        foreach ($regexes as $brand => $regex) {
            $matches = $this->matchUserAgent($regex['regex']);
            if ($matches) {
                break;
            }
        }
        if (empty($matches)) {
            return false;
        }
        if ($brand != 'Unknown') {
            $brandId = array_search($brand, self::$deviceBrands);
            if ($brandId === false) {
                // This Exception should never be thrown. If so a defined brand name is missing in $deviceBrands
                throw new \Exception("The brand with name '{$brand}' should be listed in the deviceBrands array.");
                // @codeCoverageIgnore
            }
            $this->brand = $brandId;
        }
        if (isset($regex['device']) && in_array($regex['device'], self::$deviceTypes)) {
            $this->deviceType = self::$deviceTypes[$regex['device']];
        }
        $this->model = '';
        if (isset($regex['model'])) {
            $this->model = $this->buildModel($regex['model'], $matches);
        }
        if (isset($regex['models'])) {
            foreach ($regex['models'] as $modelRegex) {
                $modelMatches = $this->matchUserAgent($modelRegex['regex']);
                if ($modelMatches) {
                    break;
                }
            }
            if (empty($modelMatches)) {
                return true;
            }
            $this->model = trim($this->buildModel($modelRegex['model'], $modelMatches));
            if (isset($modelRegex['brand']) && ($brandId = array_search($modelRegex['brand'], self::$deviceBrands))) {
                $this->brand = $brandId;
            }
            if (isset($modelRegex['device']) && in_array($modelRegex['device'], self::$deviceTypes)) {
                $this->deviceType = self::$deviceTypes[$modelRegex['device']];
            }
        }
        return true;
    }