Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
9
10final class Manager
11{
12 private static $instance = null;
14 protected $settings = null;
16 protected $collision = null;
18 protected $criterion = null;
20 protected $logger = null;
21
25 private static function getInstance()
26 {
27 if(self::$instance === null)
28 {
29 self::$instance = new static();
30 }
31 return self::$instance;
32 }
33
38 public static function createImport($typeId)
39 {
40 $config = static::getImportByType($typeId);
41
42 $import = Entity\EntityImportFactory::create($typeId);
43
44 $import->loadSettings($config->settings);
45 $import->loadCollision($config->collision);
46 $import->loadCriterion($config->criterion);
47 $import->loadLogger($config->logger);
48
49 return $import;
50 }
51
62 static public function registerInstance($typeId, ISettings $settings, ICollision $collision = null, ICriterion $criterion = null)
63 {
64 if(!is_int($typeId))
65 {
66 $typeId = (int)$typeId;
67 }
68
69 if(!EntityType::IsDefined($typeId))
70 {
71 throw new ArgumentOutOfRangeException('Is not defined', EntityType::FIRST, EntityType::LAST);
72 }
73
74 if(self::$instance[$typeId] === null)
75 {
76 $manager = new static();
77 $manager->settings = $settings;
78 $manager->collision = $collision !== null ? $collision : new ImportCollision();
79 $manager->criterion = $criterion !== null ? $criterion : new ImportCriterionBase();
80 $manager->logger = new LoggerDiag();
81
82 self::$instance[$typeId] = $manager;
83 }
84 return self::$instance[$typeId];
85 }
86
93 private static function getImportByType($typeId)
94 {
95 if(!is_int($typeId))
96 {
97 $typeId = (int)$typeId;
98 }
99
100 if(!EntityType::IsDefined($typeId))
101 {
102 throw new ArgumentOutOfRangeException('Is not defined', EntityType::FIRST, EntityType::LAST);
103 }
104
105 $import = static::getInstance();
106 return isset($import[$typeId]) ? $import[$typeId] : null;
107 }
108
114 public static function getSettingsByType($typeId)
115 {
116 if(!is_int($typeId))
117 {
118 $typeId = (int)$typeId;
119 }
120
121 if(!EntityType::IsDefined($typeId))
122 {
123 throw new ArgumentOutOfRangeException('Is not defined', EntityType::FIRST, EntityType::LAST);
124 }
125
126 $config = static::getImportByType($typeId);
127
128 return $config->settings;
129 }
130}
static getSettingsByType($typeId)
Definition manager.php:114
static createImport($typeId)
Definition manager.php:38
static registerInstance($typeId, ISettings $settings, ICollision $collision=null, ICriterion $criterion=null)
Definition manager.php:62