Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Context.php
1<?php
2
4
6
7class Context
8{
9 protected ?int $actionContextUserId = null;
10
16 public function setUser($contextUser): self
17 {
18 if (is_numeric($contextUser))
19 {
20 $this->setUserId((int)$contextUser);
21 }
22 elseif ($contextUser instanceof User)
23 {
24 $this->setUserId($contextUser->getId());
25 }
26 elseif ($contextUser === null)
27 {
28 $this->resetUser();
29 }
30
31 return $this;
32 }
33
41 public function setUserId(?int $contextUserId): self
42 {
43 if (is_numeric($contextUserId))
44 {
45 $this->actionContextUserId = (int)$contextUserId;
46 }
47 elseif ($contextUserId === null)
48 {
49 $this->resetUser();
50 }
51
52 return $this;
53 }
54
59 public function resetUser(): self
60 {
61 $this->actionContextUserId = null;
62
63 return $this;
64 }
65
70 public function getUserId(): int
71 {
72 global $USER;
73 if (
74 $this->actionContextUserId === null
75 && ($USER instanceof \CUser)
76 )
77 {
78 return (int)$USER->getId();
79 }
80
81 return (int)$this->actionContextUserId;
82 }
83
88 public function getUser(): User
89 {
90 return User::getInstance($this->getUserId());
91 }
92}
setUserId(?int $contextUserId)
Definition Context.php:41