AbstractDeviceParser.php
1 month ago
Camera.php
2 years ago
CarBrowser.php
2 years ago
Console.php
2 years ago
HbbTv.php
3 months ago
Mobile.php
2 years ago
Notebook.php
2 years ago
PortableMediaPlayer.php
2 years ago
ShellTv.php
3 months ago
HbbTv.php
66 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\Device; |
| 12 | |
| 13 | /** |
| 14 | * Class HbbTv |
| 15 | * |
| 16 | * Device parser for hbbtv detection |
| 17 | * @internal |
| 18 | */ |
| 19 | class HbbTv extends AbstractDeviceParser |
| 20 | { |
| 21 | /** |
| 22 | * @var string |
| 23 | */ |
| 24 | protected $fixtureFile = 'regexes/device/televisions.yml'; |
| 25 | /** |
| 26 | * @var string |
| 27 | */ |
| 28 | protected $parserName = 'tv'; |
| 29 | /** |
| 30 | * Parses the current UA and checks whether it contains HbbTv or SmartTvA information |
| 31 | * |
| 32 | * @return array|null |
| 33 | * |
| 34 | * @throws \Exception |
| 35 | * |
| 36 | * @see televisions.yml for list of detected televisions |
| 37 | * |
| 38 | */ |
| 39 | public function parse() : ?array |
| 40 | { |
| 41 | // only parse user agents containing fragments: hbbtv or SmartTvA |
| 42 | if (null === $this->isHbbTv()) { |
| 43 | return null; |
| 44 | } |
| 45 | parent::parse(); |
| 46 | // always set device type to tv, even if no model/brand could be found |
| 47 | if (null === $this->deviceType) { |
| 48 | $this->deviceType = self::DEVICE_TYPE_TV; |
| 49 | } |
| 50 | return $this->getResult(); |
| 51 | } |
| 52 | /** |
| 53 | * Returns if the parsed UA was identified as a HbbTV device |
| 54 | * |
| 55 | * @return string|null |
| 56 | * |
| 57 | * @throws \Exception |
| 58 | */ |
| 59 | public function isHbbTv() : ?string |
| 60 | { |
| 61 | $regex = '(?:HbbTV|SmartTvA)/([1-9]{1}(?:\\.[0-9]{1}){1,2})'; |
| 62 | $match = $this->matchUserAgent($regex); |
| 63 | return $match[1] ?? null; |
| 64 | } |
| 65 | } |
| 66 |