Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
browser.php
1<?php
2
11
12use Bitrix\Main;
14
16{
17 protected $name;
18 protected $platform;
20 protected $userAgent;
21
27 public function __construct(?string $name = null, ?string $platform = null, ?int $deviceType = null)
28 {
29 $this->name = $name;
30 $this->platform = $platform;
31 if ($deviceType !== null)
32 {
33 $this->deviceType = $deviceType;
34 }
35 }
36
40 public function getName(): ?string
41 {
42 return $this->name;
43 }
44
49 public function setName(?string $name): Browser
50 {
51 $this->name = $name;
52 return $this;
53 }
54
58 public function getPlatform(): ?string
59 {
60 return $this->platform;
61 }
62
67 public function setPlatform(?string $platform): Browser
68 {
69 $this->platform = $platform;
70 return $this;
71 }
72
76 public function getDeviceType(): int
77 {
78 return $this->deviceType;
79 }
80
85 public function setDeviceType(int $deviceType): Browser
86 {
87 $this->deviceType = $deviceType;
88 return $this;
89 }
90
94 public function getUserAgent(): ?string
95 {
96 return $this->userAgent;
97 }
98
103 public function setUserAgent(?string $userAgent)
104 {
105 $this->userAgent = $userAgent;
106 return $this;
107 }
108
113 public static function detect(?string $userAgent = null): Browser
114 {
115 $serviceLocator = DI\ServiceLocator::getInstance();
116
117 if($serviceLocator->has('main.browserDetector'))
118 {
119 $detector = $serviceLocator->get('main.browserDetector');
120 }
121 else
122 {
123 $detector = new Detector();
124 }
125
126 if ($userAgent === null)
127 {
128 $userAgent = Main\Context::getCurrent()->getServer()->getUserAgent();
129 }
130
131 return $detector->detectBrowser($userAgent);
132 }
133}
__construct(?string $name=null, ?string $platform=null, ?int $deviceType=null)
Definition browser.php:27
setPlatform(?string $platform)
Definition browser.php:67
static detect(?string $userAgent=null)
Definition browser.php:113
setDeviceType(int $deviceType)
Definition browser.php:85
setUserAgent(?string $userAgent)
Definition browser.php:103