1C-Bitrix 25.700.0
helper.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Calendar\Sync\Google;
5
6
7use Bitrix\Main\Loader;
8use Bitrix\Fileman\UserField\Types\AddressType;
9use Bitrix\Main\Config\Option;
10use DateTimeInterface;
11
12class Helper
13{
14 public const DEFAULT_HTTPS_PORT = 443;
15 public const GOOGLE_ACCOUNT_TYPE_CALDAV= 'caldav_google_oauth';
16 public const GOOGLE_ACCOUNT_TYPE_API = 'google_api_oauth';
17
18 public const CONNECTION_NAME = 'google';
19 public const HTTP_SCHEME_DEFAULT = 'https';
20 public const HTTP_SCHEME_SEPARATOR = '://';
21 public const GOOGLE_API_URL = 'www.googleapis.com';
22 public const GOOGLE_CALDAV_URL = 'apidata.googleusercontent.com';
23 public const GOOGLE_API_V3_URI = '/calendar/v3';
24 public const GOOGLE_API_V2_URI = '/calendar/v2/';
25 public const GOOGLE_SERVER_PATH_V3 = self::HTTP_SCHEME_DEFAULT . self::HTTP_SCHEME_SEPARATOR . self::GOOGLE_API_URL . self::GOOGLE_API_V3_URI;
26 public const GOOGLE_SERVER_PATH_V2 = self::HTTP_SCHEME_DEFAULT . self::HTTP_SCHEME_SEPARATOR . self::GOOGLE_CALDAV_URL . self::GOOGLE_API_V2_URI;
27 public const DATE_TIME_FORMAT = DateTimeInterface::ATOM;
28 public const DATE_TIME_FORMAT_WITH_MICROSECONDS = 'Y-m-d\TH:i:s\.vP';
29 public const DATE_TIME_FORMAT_RFC_3339 = 'Y-m-d\TH:i:s\Z';
30 public const DATE_TIME_FORMAT_WITH_UTC_TIMEZONE = 'Ymd\THis\Z';
31 public const EXCLUDED_DATE_TIME_FORMAT = self::DATE_TIME_FORMAT_WITH_UTC_TIMEZONE;
32 public const EXCLUDED_DATE_FORMAT = 'Ymd';
33 public const DATE_FORMAT = 'Y-m-d';
34 public const VERSION_DIFFERENCE = 1;
35 public const END_OF_TIME = "01.01.2038";
36
41 public function isGoogleConnection($accountType): bool
42 {
43 return in_array($accountType, [self::GOOGLE_ACCOUNT_TYPE_CALDAV, self::GOOGLE_ACCOUNT_TYPE_API], true);
44 }
45
46 public function isDeletedResource($errorText): bool
47 {
48 return !empty($errorText) && preg_match("/^(\[410\] Resource has been deleted)/i", $errorText);
49 }
50
51 public function isNotFoundError(string $errorText = null): bool
52 {
53 return !empty($errorText) && preg_match("/^\[(404)\][a-z0-9 _]*/i", $errorText);
54 }
55
56 public function isNotValidSyncTokenError(string $errorText = null): bool
57 {
58 return !empty($errorText)
59 && (preg_match("/^(\[410\] The requested minimum modification time lies too far in the past.)/i", $errorText)
60 || preg_match("/^(\[410\] Sync token is no longer valid, a full sync is required.)/i", $errorText))
61 ;
62 }
63
64 public function isMissingRequiredAuthCredential(string $errorText = null): bool
65 {
66 return !empty($errorText)
67 && (preg_match("/^\[401\] Request is missing required authentication credential.[a-z0-9 _]*/i", $errorText)
68 || preg_match("/^\[401\] Request had invalid authentication credentials.[a-z0-9 _]*/i", $errorText))
69 ;
70 }
71
72
79 public function getApiKey(): ?string
80 {
81 if (
82 Loader::includeModule('socialservices')
83 && ($apiKey = Option::get('socialservices', 'google_api_key', null))
84 )
85 {
86 return $apiKey;
87 }
88
89 if (Loader::includeModule('fileman'))
90 {
91 $apiKey = AddressType::getApiKey();
92 if (!empty($apiKey))
93 {
94 return $apiKey;
95 }
96 }
97
98 return Option::get('fileman', 'google_map_api_key', null)
99 ?? Option::get('bitrix24', 'google_map_api_key', null)
100 ;
101 }
102}
isMissingRequiredAuthCredential(string $errorText=null)
Определения helper.php:64
const VERSION_DIFFERENCE
Определения helper.php:34
isNotValidSyncTokenError(string $errorText=null)
Определения helper.php:56
const GOOGLE_SERVER_PATH_V2
Определения helper.php:26
const GOOGLE_ACCOUNT_TYPE_API
Определения helper.php:16
const DATE_TIME_FORMAT
Определения helper.php:27
const GOOGLE_ACCOUNT_TYPE_CALDAV
Определения helper.php:15
const END_OF_TIME
Определения helper.php:35
const CONNECTION_NAME
Определения helper.php:18
const DEFAULT_HTTPS_PORT
Определения helper.php:14
const EXCLUDED_DATE_FORMAT
Определения helper.php:32
const GOOGLE_SERVER_PATH_V3
Определения helper.php:25
const GOOGLE_API_V3_URI
Определения helper.php:23
const DATE_FORMAT
Определения helper.php:33
const GOOGLE_CALDAV_URL
Определения helper.php:22
const DATE_TIME_FORMAT_WITH_UTC_TIMEZONE
Определения helper.php:30
isNotFoundError(string $errorText=null)
Определения helper.php:51
const EXCLUDED_DATE_TIME_FORMAT
Определения helper.php:31
const DATE_TIME_FORMAT_WITH_MICROSECONDS
Определения helper.php:28
isGoogleConnection($accountType)
Определения helper.php:41
isDeletedResource($errorText)
Определения helper.php:46
const GOOGLE_API_V2_URI
Определения helper.php:24
const DATE_TIME_FORMAT_RFC_3339
Определения helper.php:29
const GOOGLE_API_URL
Определения helper.php:21
const HTTP_SCHEME_DEFAULT
Определения helper.php:19
const HTTP_SCHEME_SEPARATOR
Определения helper.php:20