Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
codebasedfactory.php
1<?php
10
12
17abstract class CodeBasedFactory
18{
19 protected static $instances = array();
20 protected static $classNames = array();
21
22 public static function reset()
23 {
24 static::$instances = array();
25 static::$classNames = array();
26 }
27
28 protected static function getClasses()
29 {
30 return array();
31 }
32
33 protected static function getObjectInstance($interface, $code)
34 {
35 $classList = static::getObjectClassList($interface);
36 foreach ($classList as $className)
37 {
38 if ($code == $className::CODE)
39 {
40 return new $className();
41 }
42 }
43
44 return null;
45 }
46
47 protected static function getObjectInstances($interface)
48 {
50 $eventName = $interface::EVENT_NAME;
51 if (isset(static::$instances[$eventName]))
52 {
53 return static::$instances[$eventName];
54 }
55
56 static::$instances[$eventName] = array();
57 $classList = static::getObjectClassList($interface);
58 foreach ($classList as $className)
59 {
60 static::$instances[$eventName][] = new $className();
61 }
62
63 return static::$instances[$eventName];
64 }
65
66 protected static function getObjectClassList($interface)
67 {
68 $interfaceCode = $interface;
70 $eventName = $interface::EVENT_NAME;
71 if (isset(static::$classNames[$eventName]))
72 {
73 return static::$classNames[$eventName];
74 }
75
76 static::$classNames[$eventName] = array();
77 $classList = static::getClasses();
78 $classList = isset($classList[$eventName]) ? $classList[$eventName] : array();
79 foreach ($classList as $className)
80 {
81 $interfaces = class_implements($className);
82 if ($interfaces && isset($interfaces[$interfaceCode]))
83 {
84 static::$classNames[$eventName][] = $className;
85 }
86 }
87
88 return static::$classNames[$eventName];
89 }
90}
static getObjectInstance($interface, $code)