Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ContextCustomer.php
1<?php
2
3namespace Bitrix\Im\V2\Common;
4
7
11trait ContextCustomer
12{
13 protected ?Context $context = null;
14
20 public function withContext(?Context $context): self
21 {
22 $copy = clone $this;
23
24 return $copy->setContext($context);
25 }
26
32 public function withContextUser($user): self
33 {
34 if ($this->context)
35 {
36 $context = clone $this->context;
37 }
38 else
39 {
40 $context = new Context;
41 }
42
43 if ($user instanceof User)
44 {
45 $context->setUser($user);
46 }
47 elseif (is_numeric($user))
48 {
49 $context->setUserId((int)$user);
50 }
51
52 return $this->withContext($context);
53 }
54
60 public function setContext(?Context $context): self
61 {
62 $this->context = $context;
63
64 return $this;
65 }
66
71 public function getContext(): Context
72 {
73 if ($this->context)
74 {
75 return $this->context;
76 }
77
78 return \Bitrix\Im\V2\Service\Locator::getContext();
79 }
80}
setUserId(?int $contextUserId)
Definition Context.php:41
withContext(?Context $context)
setContext(?Context $context)