Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
controller.php
1<?php
2
4
8
14{
15 public const CODE_DISK = 'disk';
16 public const CODE_IO = 'io';
17 private const ITEM_LIST = [
18 self::CODE_DISK => Disk\Base::class,
19 self::CODE_IO => IO\Base::class,
20 ];
21
22 private $errorList = [];
23
25 private static $instance;
26
30 public static function getInstance(): Controller
31 {
32 if (self::$instance === null)
33 {
34 self::$instance = new Controller();
35 }
36
37 return self::$instance;
38 }
39
48 public function get(string $code, array $setting = []): ?ProviderBase
49 {
50 $result = null;
51
52 $class = self::ITEM_LIST[$code];
53 if ($class)
54 {
55 $result = $this->getProvider($class, $setting);
56 }
57
58 return $result;
59 }
60
61 private function getProvider(string $class, array $setting = []): ?ProviderBase
62 {
63 $result = null;
64 if ($class && class_exists($class))
65 {
66 $this->resetErrors();
67 try
68 {
69 $object = new $class($setting);
70 if ($object instanceof ProviderBase)
71 {
72 $result = $object;
73 }
74 }
75 catch (SystemException $error)
76 {
77 $this->setError($error->getCode(), $error->getMessage());
78 }
79 }
80
81 return $result;
82 }
83
84 private function __construct()
85 {
86 }
87
88 private function __clone()
89 {
90 }
91
92 private function setError($code, $message): void
93 {
94 $this->errorList[$code] = $message;
95 }
96
97 private function resetErrors(): bool
98 {
99 $this->errorList = [];
100
101 return true;
102 }
103
104 public function listError(): array
105 {
106 return $this->errorList;
107 }
108}