Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
registry.php
1
<?php
2
3
namespace
Bitrix\Main\UserField\Internal
;
4
5
use
Bitrix\Main\EventManager
;
6
use
Bitrix\Main\ORM\Entity
;
7
11
final
class
Registry
12
{
13
const
EVENT_NAME
=
'onGetUserFieldTypeFactory'
;
14
16
protected
$factories
= [];
17
protected
$itemTypes
= [];
18
20
private
static
$instance;
21
22
private
function
__construct()
23
{
24
$this->
addFactoriesByEvent
();
25
}
26
27
private
function
__clone()
28
{
29
}
30
35
public
static
function
getInstance
():
Registry
36
{
37
if
(!isset(self::$instance))
38
{
39
self::$instance =
new
Registry
;
40
}
41
42
return
self::$instance;
43
}
44
45
public
function
registerFactory
(
TypeFactory
$factory)
46
{
47
$this->factories[$factory->
getCode
()] = $factory;
48
}
49
54
public
function
registerTypeByEntity
(
Entity
$entity, array $type): void
55
{
56
$this->itemTypes[$entity->
getName
()] = $type;
57
}
58
63
public
function
getTypeByEntity
(
Entity
$entity): ?array
64
{
65
$entityName = $entity->
getName
();
66
if
(isset($this->itemTypes[$entityName]))
67
{
68
return
$this->itemTypes[$entityName];
69
}
70
71
return
null
;
72
}
73
74
public
function
getFactoryByCode
(
string
$code): ?
TypeFactory
75
{
76
if
(isset($this->factories[$code]))
77
{
78
return
$this->factories[$code];
79
}
80
81
return
null
;
82
}
83
84
public
function
getFactoryByTypeDataClass
($typeDataClass): ?
TypeFactory
85
{
86
foreach
($this->factories as $factory)
87
{
88
if
($factory->getTypeDataClass() == $typeDataClass)
89
{
90
return
$factory;
91
}
92
}
93
94
return
null
;
95
}
96
101
public
function
getUserFieldEntityIdByItemEntity
(
Entity
$entity): ?string
102
{
103
$type = $this->
getTypeByEntity
($entity);
104
if
($type && $type[
'code'
])
105
{
106
$factory = $this->
getFactoryByCode
($type[
'code'
]);
107
if
($factory)
108
{
109
return
$factory->getUserFieldEntityId($type[
'ID'
]);
110
}
111
}
112
113
return
null
;
114
}
115
116
protected
function
addFactoriesByEvent
(): void
117
{
118
foreach
(
EventManager::getInstance
()->findEventHandlers(
'main'
, static::EVENT_NAME) as $handler)
119
{
120
$eventResult = ExecuteModuleEventEx($handler);
121
if
(is_array($eventResult))
122
{
123
foreach
($eventResult as $factory)
124
{
125
if
($factory instanceof
TypeFactory
)
126
{
127
$this->
registerFactory
($factory);
128
}
129
}
130
}
131
}
132
}
133
}
Bitrix\Main\EventManager
Definition
eventmanager.php:15
Bitrix\Main\EventManager\getInstance
static getInstance()
Definition
eventmanager.php:33
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Main\ORM\Entity\getName
getName()
Definition
entity.php:661
Bitrix\Main\UserField\Internal\Registry
Definition
registry.php:12
Bitrix\Main\UserField\Internal\Registry\$itemTypes
$itemTypes
Definition
registry.php:17
Bitrix\Main\UserField\Internal\Registry\addFactoriesByEvent
addFactoriesByEvent()
Definition
registry.php:116
Bitrix\Main\UserField\Internal\Registry\getFactoryByTypeDataClass
getFactoryByTypeDataClass($typeDataClass)
Definition
registry.php:84
Bitrix\Main\UserField\Internal\Registry\getUserFieldEntityIdByItemEntity
getUserFieldEntityIdByItemEntity(Entity $entity)
Definition
registry.php:101
Bitrix\Main\UserField\Internal\Registry\EVENT_NAME
const EVENT_NAME
Definition
registry.php:13
Bitrix\Main\UserField\Internal\Registry\registerFactory
registerFactory(TypeFactory $factory)
Definition
registry.php:45
Bitrix\Main\UserField\Internal\Registry\registerTypeByEntity
registerTypeByEntity(Entity $entity, array $type)
Definition
registry.php:54
Bitrix\Main\UserField\Internal\Registry\getFactoryByCode
getFactoryByCode(string $code)
Definition
registry.php:74
Bitrix\Main\UserField\Internal\Registry\$factories
$factories
Definition
registry.php:16
Bitrix\Main\UserField\Internal\Registry\getTypeByEntity
getTypeByEntity(Entity $entity)
Definition
registry.php:63
Bitrix\Main\UserField\Internal\Registry\getInstance
static getInstance()
Definition
registry.php:35
Bitrix\Main\UserField\Internal\TypeFactory
Definition
typefactory.php:9
Bitrix\Main\UserField\Internal\TypeFactory\getCode
getCode()
Bitrix\Main\UserField\Internal
Definition
item.php:3
modules
main
lib
userfield
internal
registry.php
Создано системой
1.10.0