1*d5ef99ddSAndreas Gohr<?php 2*d5ef99ddSAndreas Gohr 3*d5ef99ddSAndreas Gohr/** 4*d5ef99ddSAndreas Gohr * Device Detector - The Universal Device Detection library for parsing User Agents 5*d5ef99ddSAndreas Gohr * 6*d5ef99ddSAndreas Gohr * @link https://matomo.org 7*d5ef99ddSAndreas Gohr * 8*d5ef99ddSAndreas Gohr * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later 9*d5ef99ddSAndreas Gohr */ 10*d5ef99ddSAndreas Gohr 11*d5ef99ddSAndreas Gohrdeclare(strict_types=1); 12*d5ef99ddSAndreas Gohr 13*d5ef99ddSAndreas Gohrnamespace DeviceDetector\Parser; 14*d5ef99ddSAndreas Gohr 15*d5ef99ddSAndreas Gohr/** 16*d5ef99ddSAndreas Gohr * Class VendorFragments 17*d5ef99ddSAndreas Gohr * 18*d5ef99ddSAndreas Gohr * Device parser for vendor fragment detection 19*d5ef99ddSAndreas Gohr */ 20*d5ef99ddSAndreas Gohrclass VendorFragment extends AbstractParser 21*d5ef99ddSAndreas Gohr{ 22*d5ef99ddSAndreas Gohr /** 23*d5ef99ddSAndreas Gohr * @var string 24*d5ef99ddSAndreas Gohr */ 25*d5ef99ddSAndreas Gohr protected $fixtureFile = 'regexes/vendorfragments.yml'; 26*d5ef99ddSAndreas Gohr 27*d5ef99ddSAndreas Gohr /** 28*d5ef99ddSAndreas Gohr * @var string 29*d5ef99ddSAndreas Gohr */ 30*d5ef99ddSAndreas Gohr protected $parserName = 'vendorfragments'; 31*d5ef99ddSAndreas Gohr 32*d5ef99ddSAndreas Gohr /** 33*d5ef99ddSAndreas Gohr * @var string 34*d5ef99ddSAndreas Gohr */ 35*d5ef99ddSAndreas Gohr protected $matchedRegex = null; 36*d5ef99ddSAndreas Gohr 37*d5ef99ddSAndreas Gohr /** 38*d5ef99ddSAndreas Gohr * @inheritdoc 39*d5ef99ddSAndreas Gohr */ 40*d5ef99ddSAndreas Gohr public function parse(): ?array 41*d5ef99ddSAndreas Gohr { 42*d5ef99ddSAndreas Gohr foreach ($this->getRegexes() as $brand => $regexes) { 43*d5ef99ddSAndreas Gohr foreach ($regexes as $regex) { 44*d5ef99ddSAndreas Gohr if ($this->matchUserAgent($regex . '[^a-z0-9]+')) { 45*d5ef99ddSAndreas Gohr $this->matchedRegex = $regex; 46*d5ef99ddSAndreas Gohr 47*d5ef99ddSAndreas Gohr return ['brand' => $brand]; 48*d5ef99ddSAndreas Gohr } 49*d5ef99ddSAndreas Gohr } 50*d5ef99ddSAndreas Gohr } 51*d5ef99ddSAndreas Gohr 52*d5ef99ddSAndreas Gohr return null; 53*d5ef99ddSAndreas Gohr } 54*d5ef99ddSAndreas Gohr 55*d5ef99ddSAndreas Gohr /** 56*d5ef99ddSAndreas Gohr * @return string|null 57*d5ef99ddSAndreas Gohr */ 58*d5ef99ddSAndreas Gohr public function getMatchedRegex(): ?string 59*d5ef99ddSAndreas Gohr { 60*d5ef99ddSAndreas Gohr return $this->matchedRegex; 61*d5ef99ddSAndreas Gohr } 62*d5ef99ddSAndreas Gohr} 63