1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Context.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Application;
4
5use Bitrix\Main\Application;
6
7class Context
8{
9 private const DESKTOP_API_VERSION_GET_PARAMETER = 'BXD_API_VERSION';
10 private const DESKTOP_USER_AGENT = 'BitrixDesktop';
11 private const MOBILE_USER_AGENT = 'BitrixMobile';
12
13 private \Bitrix\Main\Context $context;
14
15 public function __construct(\Bitrix\Main\Context $context)
16 {
17 $this->context = $context;
18 }
19
20 public static function getCurrent(): static
21 {
22 return new static(Application::getInstance()->getContext());
23 }
24
25 public function isDesktop(): bool
26 {
27 return
28 $this->context->getRequest()->getQuery(self::DESKTOP_API_VERSION_GET_PARAMETER)
29 || $this->containInUserAgent(self::DESKTOP_USER_AGENT)
30 ;
31 }
32
33 public function isMobile(): bool
34 {
35 return $this->containInUserAgent(self::MOBILE_USER_AGENT);
36 }
37
38 private function containInUserAgent(string $userAgent): bool
39 {
40 return stripos($this->context->getRequest()->getUserAgent() ?? '', $userAgent) !== false;
41 }
42}
static getCurrent()
Определения Context.php:20
__construct(\Bitrix\Main\Context $context)
Определения Context.php:15
static getInstance()
Определения servicelocator.php:33