Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
FieldAccessImplementation.php
1<?php
2
3namespace Bitrix\Im\V2\Common;
4
9trait FieldAccessImplementation
10{
11 public function offsetExists($offset): bool
12 {
13 return isset(static::mirrorDataEntityFields()[$offset]);
14 }
15
16 public function offsetGet($offset)
17 {
18 if ($field = static::mirrorDataEntityFields()[$offset])
19 {
20 if (isset($field['alias']))
21 {
22 $field = static::mirrorDataEntityFields()[$field['alias']];
23 }
24 if (
25 ($getter = $field['get'])
26 && is_string($getter)
27 && is_callable([$this, $getter])
28 )
29 {
30 return $this->$getter();
31 }
32
33 return $this->{$field['field']};
34 }
35
36 return null;
37 }
38
39 public function offsetSet($offset, $value): void
40 {
41 if ($field = static::mirrorDataEntityFields()[$offset])
42 {
43 if (isset($field['alias']))
44 {
45 $field = static::mirrorDataEntityFields()[$field['alias']];
46 }
47 if (!isset($field['primary']))
48 {
49 if (
50 ($setter = $field['set'])
51 && is_string($setter)
52 && is_callable([$this, $setter])
53 )
54 {
55 $this->$setter($value);
56 }
57 else
58 {
59 $this->{$field['field']} = $value;
60 }
61 }
62 }
63 }
64
65 public function offsetUnset($offset): void
66 {
67 if ($field = static::mirrorDataEntityFields()[$offset])
68 {
69 if (isset($field['alias']))
70 {
71 $field = static::mirrorDataEntityFields()[$field['alias']];
72 }
73 if (!isset($field['primary']))
74 {
75 $this->{$field['field']} = null;
76 }
77 }
78 }
79}