1: <?php
2: /**
3: * Definition of the short functions for the more confortable programming
4: * and code elegance.
5: *
6: * @package System
7: *
8: * @author Oleg Schildt
9: */
10:
11: namespace SmartFactory;
12:
13: use \SmartFactory\Interfaces\ILanguageManager;
14: use \SmartFactory\Interfaces\IMessageManager;
15: use \SmartFactory\Interfaces\ISessionManager;
16: use \SmartFactory\Interfaces\IDebugProfiler;
17: use \SmartFactory\Interfaces\IEventManager;
18: use \SmartFactory\Interfaces\IShardManager;
19:
20: /**
21: * Short function that provides the text translation for
22: * the text ID for the given language.
23: *
24: * @param string $text_id
25: * Text ID
26: *
27: * @param string $lng
28: * The language. If it is not specified,
29: * the default language is used.
30: *
31: * @param string $default_text
32: * The default text to be used if there is no translation.
33: *
34: * @return string
35: * Returns the translation text or the $text_id if no translation
36: * is found.
37: *
38: * @throws \Exception
39: * It might throw the following exceptions in the case of any errors:
40: *
41: * - if the interface or class is not specified.
42: * - if the interface or class does not exist.
43: * - if the check of the classes and interfaces fails.
44: *
45: * @author Oleg Schildt
46: */
47: function text(string $text_id, string $lng = "", string $default_text = ""): string
48: {
49: return singleton(ILanguageManager::class)->text($text_id, $lng, $default_text);
50: } // text
51:
52: /**
53: * Short function for getting the instance of the IMessageManager.
54: *
55: * @return IMessageManager
56: * Returns the instance of the IMessageManager.
57: *
58: * @throws \Exception
59: * It might throw the following exceptions in the case of any errors:
60: *
61: * - if the interface or class is not specified.
62: * - if the interface or class does not exist.
63: * - if the check of the classes and interfaces fails.
64: *
65: * @author Oleg Schildt
66: */
67: function messenger(): IMessageManager
68: {
69: return singleton(IMessageManager::class);
70: } // messenger
71:
72: /**
73: * Short function for getting the instance of the IDebugProfiler.
74: *
75: * @return IDebugProfiler
76: * Returns the instance of the IDebugProfiler.
77: *
78: * @throws \Exception
79: * It might throw the following exceptions in the case of any errors:
80: *
81: * - if the interface or class is not specified.
82: * - if the interface or class does not exist.
83: * - if the check of the classes and interfaces fails.
84: *
85: * @author Oleg Schildt
86: */
87: function debugger(): IDebugProfiler
88: {
89: return singleton(IDebugProfiler::class);
90: } // debugger
91:
92: /**
93: * Short function for writing debug messages to the log.
94: *
95: * @param string $msg
96: * The message to be logged.
97: *
98: * @return void
99: *
100: * @throws \Exception
101: * It might throw the following exceptions in the case of any errors:
102: *
103: * - if the interface or class is not specified.
104: * - if the interface or class does not exist.
105: * - if the check of the classes and interfaces fails.
106: * - if the debug file is not writable.
107: *
108: * @author Oleg Schildt
109: */
110: function debug_message($msg): void
111: {
112: singleton(IDebugProfiler::class)->debugMessage($msg);
113: } // debug_message
114:
115: /**
116: * Short function for getting the instance of the IEventManager.
117: *
118: * @return IEventManager
119: * Returns the instance of the IEventManager.
120: *
121: * @throws \Exception
122: * It might throw the following exceptions in the case of any errors:
123: *
124: * - if the interface or class is not specified.
125: * - if the interface or class does not exist.
126: * - if the check of the classes and interfaces fails.
127: *
128: * @author Oleg Schildt
129: */
130: function event(): IEventManager
131: {
132: return singleton(IEventManager::class);
133: } // event
134:
135: /**
136: * Short function for getting the instance of the ConfigSettingsManager.
137: *
138: * @return ConfigSettingsManager
139: * Returns the instance of the ConfigSettingsManager.
140: *
141: * @throws \Exception
142: * It might throw the following exceptions in the case of any errors:
143: *
144: * - if the interface or class is not specified.
145: * - if the interface or class does not exist.
146: * - if the check of the classes and interfaces fails.
147: *
148: * @author Oleg Schildt
149: */
150: function config_settings(): ConfigSettingsManager
151: {
152: return singleton(ConfigSettingsManager::class);
153: } // config_settings
154:
155: /**
156: * Short function for getting the instance of the RuntimeSettingsManager.
157: *
158: * @return RuntimeSettingsManager
159: * Returns the instance of the RuntimeSettingsManager.
160: *
161: * @throws \Exception
162: * It might throw the following exceptions in the case of any errors:
163: *
164: * - if the interface or class is not specified.
165: * - if the interface or class does not exist.
166: * - if the check of the classes and interfaces fails.
167: *
168: * @author Oleg Schildt
169: */
170: function runtime_settings(): RuntimeSettingsManager
171: {
172: return singleton(RuntimeSettingsManager::class);
173: } // runtime_settings
174:
175: /**
176: * Short function for getting the instance of the UserSettingsManager.
177: *
178: * @return UserSettingsManager
179: * Returns the instance of the UserSettingsManager.
180: *
181: * @throws \Exception
182: * It might throw the following exceptions in the case of any errors:
183: *
184: * - if the interface or class is not specified.
185: * - if the interface or class does not exist.
186: * - if the check of the classes and interfaces fails.
187: *
188: * @author Oleg Schildt
189: */
190: function user_settings(): UserSettingsManager
191: {
192: return singleton(UserSettingsManager::class);
193: } // user_settings
194:
195: /**
196: * Short function for requesting the dbworker connected to the specified shard.
197: *
198: * @param string $shard_name
199: * The name of the shard.
200: *
201: * @return ?\SmartFactory\DatabaseWorkers\DBWorker
202: * returns DBWorker object or null if the object could not be created.
203: *
204: * @throws \Exception
205: * It might throw the following exceptions in the case of any errors:
206: *
207: * - if the interface or class does not exist.
208: * - if the shard was not found.
209: * - if the check of the classes and interfaces fails.
210: * - if the php extension is not installed.
211: * - db_missing_type_error - if the database type is not specified.
212: * - db_conn_data_error - if the connection parameters are incomplete.
213: * - db_server_conn_error - if the database server cannot be connected.
214: * - db_not_exists_error - if database does not exists od inaccesible to the user.
215: *
216: * @author Oleg Schildt
217: */
218: function dbshard(string $shard_name): ?\SmartFactory\DatabaseWorkers\DBWorker
219: {
220: return singleton(IShardManager::class)->dbshard($shard_name);
221: } // dbshard
222:
223: /**
224: * Short function for requesting the dbworker connected to the specified shard,
225: * that is chosen randomly for load balancing reason.
226: *
227: * @param string $load_balancing_group
228: * The name of the shard.
229: *
230: * @return ?\SmartFactory\DatabaseWorkers\DBWorker
231: * returns DBWorker object or null if the object could not be created.
232: *
233: * @throws \Exception
234: * It might throw the following exceptions in the case of any errors:
235: *
236: * - if the load balancing group was not found.
237: * - db_server_conn_error - if the database server cannot be connected.
238: * - db_not_exists_error - if database does not exists od inaccesible to the user.
239: *
240: * @author Oleg Schildt
241: */
242: function randomDBShard(string $load_balancing_group): ?\SmartFactory\DatabaseWorkers\DBWorker
243: {
244: return singleton(IShardManager::class)->randomDBShard($load_balancing_group);
245: } // randomDBShard