Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
typemanager.php
1<?php
2
4
8
10abstract class TypeManager
11{
13 static public function getTypesInternal()
14 {
15 if (! $types =& static::$types)
16 {
17 $event = static::$event;
18 $checkModule = static::$checkModule;
19
20 foreach (EventManager::getInstance()->findEventHandlers('conversion', $event) as $handler)
21 {
22 $result = ExecuteModuleEventEx($handler);
23
24 if (! is_array($result))
25 throw new SystemException('Not array returned from: '.print_r($handler, true));
26
27 foreach ($result as $name => $type)
28 {
29 if (! is_array($type))
30 throw new SystemException('Not array in: '.$event.'()['.$name.'] => '.print_r($handler, true));
31
32 if ($checkModule)
33 {
34 if (! $type['MODULE'])
35 throw new SystemException('No [MODULE] in: '.$event.'()['.$name.'] => '.print_r($handler, true));
36 }
37
38 if ($types[$name])
39 throw new SystemException('Duplicate in: '.$event.'()['.$name.'] => '.print_r($handler, true));
40
41 $types[$name] = $type;
42 }
43 }
44 }
45
46 return $types;
47 }
48
49 static public function getTypes(array $filter = null)
50 {
51 if (! $types =& static::$types)
52 {
53 static::getTypesInternal();
54 }
55
56 if (! static::$ready)
57 {
58 static::$ready = true;
59
60 uasort($types, function ($a, $b)
61 {
62 $a = $a['SORT'];
63 $b = $b['SORT'];
64
65 return $a < $b ? -1 : ($a > $b ? 1 : 0);
66 });
67
68 if (static::$checkModule)
69 {
70 $modules = Config::getModules();
71 foreach ($types as & $type)
72 {
73 $module = $modules[$type['MODULE']];
74 $type['ACTIVE'] = $module && $module['ACTIVE'];
75 }
76 unset($type);
77 }
78 }
79
80 if ($filter)
81 {
82 $count = count($filter);
83
84 return array_filter($types, function (array $type) use ($count, $filter)
85 {
86 return $count == count(array_intersect_assoc($filter, $type));
87 });
88 }
89 else
90 {
91 return $types;
92 }
93 }
94
96 static public function isTypeActive($name)
97 {
98 $types = static::getTypes();
99 $type = $types[$name];
100 return $type && $type['ACTIVE'];
101 }
102}
static getTypes(array $filter=null)