independent-analytics
/
vendor
/
matomo
/
device-detector
/
Parser
/
Client
/
Browser
Last commit date
Engine
3 months ago
Engine.php
7 months ago
Engine.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Device Detector - The Universal Device Detection library for parsing User Agents |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * |
| 8 | * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later |
| 9 | */ |
| 10 | declare (strict_types=1); |
| 11 | namespace IAWPSCOPED\DeviceDetector\Parser\Client\Browser; |
| 12 | |
| 13 | use IAWPSCOPED\DeviceDetector\Parser\Client\AbstractClientParser; |
| 14 | /** |
| 15 | * Class Engine |
| 16 | * |
| 17 | * Client parser for browser engine detection |
| 18 | * @internal |
| 19 | */ |
| 20 | class Engine extends AbstractClientParser |
| 21 | { |
| 22 | /** |
| 23 | * @var string |
| 24 | */ |
| 25 | protected $fixtureFile = 'regexes/client/browser_engine.yml'; |
| 26 | /** |
| 27 | * @var string |
| 28 | */ |
| 29 | protected $parserName = 'browserengine'; |
| 30 | /** |
| 31 | * Known browser engines mapped to their internal short codes |
| 32 | * |
| 33 | * @var array |
| 34 | */ |
| 35 | protected static $availableEngines = ['WebKit', 'Blink', 'Trident', 'Text-based', 'Dillo', 'iCab', 'Elektra', 'Presto', 'Clecko', 'Gecko', 'KHTML', 'NetFront', 'Edge', 'NetSurf', 'Servo', 'Goanna', 'EkiohFlow', 'Arachne', 'LibWeb', 'Maple', 'ArkWeb']; |
| 36 | /** |
| 37 | * Returns list of all available browser engines |
| 38 | * @return array |
| 39 | */ |
| 40 | public static function getAvailableEngines() : array |
| 41 | { |
| 42 | return self::$availableEngines; |
| 43 | } |
| 44 | /** |
| 45 | * @inheritdoc |
| 46 | */ |
| 47 | public function parse() : ?array |
| 48 | { |
| 49 | $matches = \false; |
| 50 | foreach ($this->getRegexes() as $regex) { |
| 51 | $matches = $this->matchUserAgent($regex['regex']); |
| 52 | if ($matches) { |
| 53 | break; |
| 54 | } |
| 55 | } |
| 56 | if (empty($matches) || empty($regex)) { |
| 57 | return null; |
| 58 | } |
| 59 | $name = $this->buildByMatch($regex['name'], $matches); |
| 60 | foreach (self::getAvailableEngines() as $engineName) { |
| 61 | if (\strtolower($name) === \strtolower($engineName)) { |
| 62 | return ['engine' => $engineName]; |
| 63 | } |
| 64 | } |
| 65 | // This Exception should never be thrown. If so a defined browser name is missing in $availableEngines |
| 66 | throw new \Exception(\sprintf('Detected browser engine was not found in $availableEngines. Tried to parse user agent: %s', $this->userAgent)); |
| 67 | // @codeCoverageIgnore |
| 68 | } |
| 69 | } |
| 70 |