Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
2
4
8
13abstract class Base implements IErrorable
14{
15 private $event;
16 private static $instances = array();
17 protected $errors;
18 protected static $result;
19
23 protected abstract function getEventTypeKey();
24
28 abstract public function call();
29
30 public function getErrors()
31 {
32 return $this->errors;
33 }
34
40 public static function getInstance()
41 {
42 $class = get_called_class();
43 if (!isset(self::$instances[$class]))
44 {
45 self::$instances[$class] = new $class();
46 }
47 return self::$instances[$class];
48 }
49
54 protected function __construct()
55 {
56 }
57
61 protected function getEvent()
62 {
63 return $this->event;
64 }
65
72 private function __clone()
73 {
74 }
75
79 private function collect()
80 {
81 $moduleId = Common::MODULE_NAME;
82 $event = new Event($moduleId, $this->getEventTypeKey());
83 $event->send();
84 $this->event = $event;
85 return $this;
86 }
87
91 protected function getModuleId()
92 {
93 return Common::MODULE_NAME;
94 }
95
96
100 protected function getResult()
101 {
102 //TODO: maybe should add here some physical caching ?!!!!!!!!
103 $class = $this->getManagerClassName();
104 if (!isset($this->result[$class]))
105 {
106 $this->collect();
107 $results = $this->getEvent()->getResults();
108 static::$result[$class] = array();
109 foreach ($results as $result)
110 {
111 $params = $result->getParameters();
112 foreach ($params as $param)
113 {
114 static::$result[$class][] = $param;
115 }
116 }
117 }
118 return static::$result[$class];
119 }
120
124 private function getManagerClassName()
125 {
126 return get_called_class();
127 }
128}