Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accesscode.php
1<?php
10
11
13{
14 public const
17
18 public const
19 AC_DEPARTMENT = '^(D)(\d+)$',
20 AC_ALL_DEPARTMENT = '^(DR)(\d+)$',
21 AC_INTRANET_USER = '^(IU)(\d+)$',
22 AC_GROUP = '^(G)(\d+)$',
23 AC_USER = '^(U)(\d+)$',
24 AC_SOCNETGROUP = '^(SG)(\d+)(_[AEK])?$',
25 AC_SOCNETUSER = '^(SU)(\d+)(_M)?$',
26 AC_CHAT = '^(CHAT)(\d+)$',
27 AC_ACCESS_DIRECTOR = '^('.self::ACCESS_DIRECTOR.')(\d+)?$',
28 AC_ACCESS_EMPLOYEE = '^('.self::ACCESS_EMPLOYEE.')(\d+)?$';
29
30 public const
31 TYPE_USER = 'users',
32 TYPE_USER_ALL = 'users_all',
33 TYPE_GROUP = 'groups',
34 TYPE_SOCNETGROUP = 'sonetgroups',
35 TYPE_DEPARTMENT = 'departments',
36 TYPE_ACCESS_DIRECTOR = 'access_director',
37 TYPE_ACCESS_EMPLOYEE = 'access_employee',
38 TYPE_CHAT = 'chat',
39 TYPE_OTHER = 'other';
40
41 public static $map = [
42 self::AC_DEPARTMENT => self::TYPE_DEPARTMENT,
43 self::AC_ALL_DEPARTMENT => self::TYPE_DEPARTMENT,
44 self::AC_INTRANET_USER => self::TYPE_USER,
45 self::AC_GROUP => self::TYPE_GROUP,
46 self::AC_USER => self::TYPE_USER,
47 self::AC_SOCNETGROUP => self::TYPE_SOCNETGROUP,
48 self::AC_SOCNETUSER => self::TYPE_OTHER,
49 self::AC_CHAT => self::TYPE_CHAT,
50 self::AC_ACCESS_DIRECTOR => self::TYPE_ACCESS_DIRECTOR,
51 self::AC_ACCESS_EMPLOYEE => self::TYPE_ACCESS_EMPLOYEE,
52 ];
53
54 private $accessCode;
55
56 private $parsed = false;
57 private $entityType = self::TYPE_OTHER;
58 private $entityPrefix = '';
59 private $entityId = 0;
60
65 public static function isValid($code): bool
66 {
67 foreach (self::$map as $pattern => $type)
68 {
69 if (preg_match('/'. $pattern .'/', $code, $matches))
70 {
71 return true;
72 }
73 }
74
75 return false;
76 }
77
81 public function __construct(string $accessCode)
82 {
83 $this->accessCode = $accessCode;
84 $this->parse();
85 }
86
90 public function getSignature(): ?string
91 {
92 if (!$this->parsed)
93 {
94 return null;
95 }
96 return $this->entityPrefix . $this->entityId;
97 }
98
102 public function getEntityType(): string
103 {
104 return $this->entityType;
105 }
106
110 public function getEntityPrefix(): string
111 {
112 return $this->entityPrefix;
113 }
114
118 public function getEntityId(): int
119 {
120 return $this->entityId;
121 }
122
126 private function parse()
127 {
128 foreach (self::$map as $pattern => $type)
129 {
130 if (preg_match('/'. $pattern .'/', $this->accessCode, $matches))
131 {
132 $this->parsed = true;
133 $this->entityType = $type;
134 $this->entityPrefix = (string) $matches[1];
135 if (array_key_exists('2', $matches))
136 {
137 $this->entityId = (int) $matches[2];
138 }
139 return;
140 }
141 }
142 }
143}
__construct(string $accessCode)