PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.6
VikBooking Hotel Booking Engine & PMS v1.8.6
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / src / factory.php

factory.php in VikBooking Hotel Booking Engine & PMS 1.8.6, at admin/helpers/src/factory.php

342 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 JPluginHelper::importPlugin('vikbooking');
15
16 /**
17 * Factory application class.
18 *
19 * @since 1.15 (J) - 1.5 (WP)
20 */
21 final class VBOFactory
22 {
23 /**
24 * Application configuration handler.
25 *
26 * @var VBOConfigRegistry
27 */
28 private static $config;
29
30 /**
31 * Application platform handler.
32 *
33 * @var VBOPlatformInterface
34 */
35 private static $platform;
36
37 /**
38 * Cron jobs factory instance.
39 *
40 * @var VBOCronFactory
41 */
42 private static $cronFactory;
43
44 /**
45 * Notification Center handler instance.
46 *
47 * @var VBONotificationCenter
48 */
49 private static $notificationCenter;
50
51 /**
52 * Crontab simulator instance.
53 *
54 * @var VBOCrontabSimulator
55 */
56 private static $crontabSimulator;
57
58 /**
59 * Task Manager instance.
60 *
61 * @var VBOTaskManager
62 */
63 private static $taskManager;
64
65 /**
66 * Class constructor.
67 * @private This object cannot be instantiated.
68 */
69 private function __construct()
70 {
71 // never called
72 }
73
74 /**
75 * Class cloner.
76 * @private This object cannot be cloned.
77 */
78 private function __clone()
79 {
80 // never called
81 }
82
83 /**
84 * Returns the current configuration object.
85 *
86 * @return VBOConfigRegistry
87 */
88 public static function getConfig()
89 {
90 // check if config class is already instantiated
91 if (is_null(static::$config))
92 {
93 // cache instantiation
94 static::$config = new VBOConfigRegistryDatabase([
95 'db' => JFactory::getDbo(),
96 ]);
97 }
98
99 return static::$config;
100 }
101
102 /**
103 * Returns the current platform handler.
104 *
105 * @return VBOPlatformInterface
106 */
107 public static function getPlatform()
108 {
109 // check if platform class is already instantiated
110 if (is_null(static::$platform))
111 {
112 if (VBOPlatformDetection::isWordPress())
113 {
114 // running WordPress platform
115 static::$platform = new VBOPlatformOrgWordpress();
116 }
117 else
118 {
119 // running Joomla platform
120 static::$platform = new VBOPlatformOrgJoomla();
121 }
122 }
123
124 return static::$platform;
125 }
126
127 /**
128 * Returns the current cron factory.
129 *
130 * @return VBOCronFactory
131 *
132 * @since 1.15.10 (J) - 1.5.10 (WP)
133 */
134 public static function getCronFactory()
135 {
136 // check if cron factory class is already instantiated
137 if (is_null(static::$cronFactory))
138 {
139 // create cron factory class and register the default folder
140 static::$cronFactory = new VBOCronFactory;
141 static::$cronFactory->setIncludePaths(VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'cronjobs');
142
143 /**
144 * Trigger hook to allow third-party plugin to register custom folders in which
145 * VikBooking should look for the creation of new cron job instances.
146 *
147 * In example:
148 * $factory->addIncludePath($path);
149 * $factory->addIncludePaths([$path1, $path2, ...]);
150 *
151 * @param VBOCronFactory $factory The cron jobs factory.
152 *
153 * @return void
154 *
155 * @since 1.15.10 (J) - 1.5.10 (WP)
156 */
157 VBOFactory::getPlatform()->getDispatcher()->trigger('onCreateCronJobsFactoryVikBooking', [static::$cronFactory]);
158 }
159
160 return static::$cronFactory;
161 }
162
163 /**
164 * Returns the current notification center instance.
165 *
166 * @return VBONotificationCenter
167 *
168 * @since 1.16.8 (J) - 1.6.8 (WP)
169 */
170 public static function getNotificationCenter()
171 {
172 // check if the notification center class is already instantiated
173 if (is_null(static::$notificationCenter))
174 {
175 // create Notification Center class
176 static::$notificationCenter = new VBONotificationCenter;
177 }
178
179 return static::$notificationCenter;
180 }
181
182 /**
183 * Returns the current crontab simulator.
184 *
185 * @return VBOCrontabSimulator
186 *
187 * @since 1.17 (J) - 1.7 (WP)
188 */
189 public static function getCrontabSimulator()
190 {
191 // check if cron factory class is already instantiated
192 if (is_null(static::$crontabSimulator)) {
193 // set up the preferred semaphore instance
194 $semaphore = new VBOCrontabSemaphoreConfig;
195
196 // set up the preferred logger instance
197 $logger = new VBOCrontabLoggerFile;
198
199 // instantiate simulator
200 static::$crontabSimulator = new VBOCrontabSimulator($semaphore, $logger);
201
202 if (VBOPlatformDetection::isJoomla()) {
203 /**
204 * Watch the automatic payments scheduled, if any.
205 * Should run every 5 minutes.
206 */
207 static::$crontabSimulator->schedule(new VBOCrontabRunnerAware('pay_schedules_watcher', 5 * 60, function(VBOCrontabLogger $logger) {
208 VBOModelPayschedules::getInstance()->watch();
209 }));
210
211 /**
212 * Run performances cleaner.
213 * Should run every week.
214 */
215 static::$crontabSimulator->schedule(new VBOCrontabRunnerAware('performance_cleaner', 60 * 60 * 24 * 7, function(VBOCrontabLogger $logger) {
216 VBOPerformanceCleaner::runCheck();
217 }));
218
219 /**
220 * Run the door-access-control framework.
221 * Should run every hour.
222 */
223 static::$crontabSimulator->schedule(new VBOCrontabRunnerAware('door_access_control', 60 * 60, function(VBOCrontabLogger $logger) {
224 // watch if any booking is approaching the check-in date
225 VBOFactory::getDoorAccessControl()->handleUpcomingArrivals();
226 // watch if passcodes get used for the first time
227 VBOFactory::getDoorAccessControl()->watchFirstAccess();
228 }));
229
230 /**
231 * Run database optimization.
232 * Should run every hour.
233 */
234 static::$crontabSimulator->schedule(new VBOCrontabRunnerAware('db_optimization', 60 * 60, function(VBOCrontabLogger $logger) {
235 VBOPerformanceCleaner::optimizeDatabase();
236 }));
237 }
238
239 if (class_exists('VCMCrontabProvider')) {
240 // in case VikChannelManager is installed, schedule the native background tasks
241 (new VCMCrontabProvider)->provide(static::$crontabSimulator);
242 }
243
244 /**
245 * Trigger hook to allow third-party plugins to register custom background tasks.
246 *
247 * The following example explains how to schedule a task that runs every hour.
248 *
249 * ```
250 * $crontab->schedule(new VBOCrontabRunnerAware('unique_id', 60 * 60, function($logger) {
251 * // do stuff
252 * }));
253 * ```
254 *
255 * @param VBOCrontabSimulator $crontab The crontab simulator instance.
256 *
257 * @return void
258 *
259 * @since 1.17 (J) - 1.7 (WP)
260 */
261 VBOFactory::getPlatform()->getDispatcher()->trigger('onSetupCrontabSimulator', [static::$crontabSimulator]);
262
263 // do not run in case we are doing an AJAX request
264 if (!strcasecmp(JFactory::getApplication()->input->server->get('HTTP_X_REQUESTED_WITH', ''), 'xmlhttprequest')) {
265 static::$crontabSimulator->stop();
266 }
267 }
268
269 return static::$crontabSimulator;
270 }
271
272 /**
273 * Returns the current task manager instance.
274 *
275 * @return VBOTaskManager
276 *
277 * @since 1.18.0 (J) - 1.8.0 (WP)
278 */
279 public static function getTaskManager()
280 {
281 // check if the object is already instantiated
282 if (is_null(static::$taskManager))
283 {
284 // create object instance
285 static::$taskManager = new VBOTaskManager;
286 }
287
288 return static::$taskManager;
289 }
290
291 /**
292 * Returns a new chat mediator instance.
293 *
294 * @return VBOChatMediator
295 *
296 * @since 1.18 (J) - 1.8 (WP)
297 */
298 public static function getChatMediator()
299 {
300 return new VBOChatMediator(new VBOChatStorageDatabase);
301 }
302
303 /**
304 * Returns a new help wizard instance.
305 *
306 * @return VBOHelpWizard
307 *
308 * @since 1.18.2 (J) - 1.8.2 (WP)
309 */
310 public static function getHelpWizard()
311 {
312 $helpWizard = new VBOHelpWizard([
313 'delay' => 0,
314 ]);
315
316 // get VikBooking configuration status
317 $metrics = VikBookingHelper::getFirstSetupMetrics();
318
319 // do not spam the user with wizard hints until the first configuration is complete
320 if (empty($metrics['totprices']) || empty($metrics['totrooms']) || empty($metrics['totdailyfares'])) {
321 return $helpWizard;
322 }
323
324 // attach the folder where the instructions should be stored
325 $helpWizard->addIncludePath(VBO_ADMIN_PATH . '/helpers/src/help/wizard/drivers/');
326
327 return $helpWizard;
328 }
329
330 /**
331 * Returns the Door Access Control instance.
332 *
333 * @return VBODooraccessFactory
334 *
335 * @since 1.18.4 (J) - 1.8.4 (WP)
336 */
337 public static function getDoorAccessControl()
338 {
339 return VBODooraccessFactory::getInstance();
340 }
341 }
342