PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.7.2
VikBooking Hotel Booking Engine & PMS v1.7.2
1.8.16 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 All 37 releases
vikbooking / admin / helpers / src / factory.php

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

246 lines 6.9 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.5
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 * Class constructor.
60 * @private This object cannot be instantiated.
61 */
62 private function __construct()
63 {
64 // never called
65 }
66
67 /**
68 * Class cloner.
69 * @private This object cannot be cloned.
70 */
71 private function __clone()
72 {
73 // never called
74 }
75
76 /**
77 * Returns the current configuration object.
78 *
79 * @return VBOConfigRegistry
80 */
81 public static function getConfig()
82 {
83 // check if config class is already instantiated
84 if (is_null(static::$config))
85 {
86 // cache instantiation
87 static::$config = new VBOConfigRegistryDatabase([
88 'db' => JFactory::getDbo(),
89 ]);
90 }
91
92 return static::$config;
93 }
94
95 /**
96 * Returns the current platform handler.
97 *
98 * @return VBOPlatformInterface
99 */
100 public static function getPlatform()
101 {
102 // check if platform class is already instantiated
103 if (is_null(static::$platform))
104 {
105 if (VBOPlatformDetection::isWordPress())
106 {
107 // running WordPress platform
108 static::$platform = new VBOPlatformOrgWordpress();
109 }
110 else
111 {
112 // running Joomla platform
113 static::$platform = new VBOPlatformOrgJoomla();
114 }
115 }
116
117 return static::$platform;
118 }
119
120 /**
121 * Returns the current cron factory.
122 *
123 * @return VBOCronFactory
124 *
125 * @since 1.5.10
126 */
127 public static function getCronFactory()
128 {
129 // check if cron factory class is already instantiated
130 if (is_null(static::$cronFactory))
131 {
132 // create cron factory class and register the default folder
133 static::$cronFactory = new VBOCronFactory;
134 static::$cronFactory->setIncludePaths(VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'cronjobs');
135
136 /**
137 * Trigger hook to allow third-party plugin to register custom folders in which
138 * VikBooking should look for the creation of new cron job instances.
139 *
140 * In example:
141 * $factory->addIncludePath($path);
142 * $factory->addIncludePaths([$path1, $path2, ...]);
143 *
144 * @param VBOCronFactory $factory The cron jobs factory.
145 *
146 * @return void
147 *
148 * @since 1.5.10
149 */
150 VBOFactory::getPlatform()->getDispatcher()->trigger('onCreateCronJobsFactoryVikBooking', [static::$cronFactory]);
151 }
152
153 return static::$cronFactory;
154 }
155
156 /**
157 * Returns the current cron notification center instance.
158 *
159 * @return VBONotificationCenter
160 *
161 * @since 1.6.8
162 */
163 public static function getNotificationCenter()
164 {
165 // check if the notification center class is already instantiated
166 if (is_null(static::$notificationCenter))
167 {
168 // create Notification Center class
169 static::$notificationCenter = new VBONotificationCenter;
170 }
171
172 return static::$notificationCenter;
173 }
174
175 /**
176 * Returns the current crontab simulator.
177 *
178 * @return VBOCrontabSimulator
179 *
180 * @since 1.7
181 */
182 public static function getCrontabSimulator()
183 {
184 // check if cron factory class is already instantiated
185 if (is_null(static::$crontabSimulator)) {
186 // set up the preferred semaphore instance
187 $semaphore = new VBOCrontabSemaphoreConfig;
188
189 // set up the preferred logger instance
190 $logger = new VBOCrontabLoggerFile;
191
192 // instantiate simulator
193 static::$crontabSimulator = new VBOCrontabSimulator($semaphore, $logger);
194
195 if (VBOPlatformDetection::isJoomla()) {
196 /**
197 * Watch the automatic payments scheduled, if any.
198 * Should run every 5 minutes.
199 */
200 static::$crontabSimulator->schedule(new VBOCrontabRunnerAware('pay_schedules_watcher', 5 * 60, function(VBOCrontabLogger $logger) {
201 VBOModelPayschedules::getInstance()->watch();
202 }));
203
204 /**
205 * Run performances cleaner.
206 * Should run every week.
207 */
208 static::$crontabSimulator->schedule(new VBOCrontabRunnerAware('performance_cleaner', 60 * 60 * 24 * 7, function(VBOCrontabLogger $logger) {
209 VBOPerformanceCleaner::runCheck();
210 }));
211 }
212
213 if (class_exists('VCMCrontabProvider')) {
214 // in case VikChannelManager is installed, schedule the native background tasks
215 (new VCMCrontabProvider)->provide(static::$crontabSimulator);
216 }
217
218 /**
219 * Trigger hook to allow third-party plugins to register custom background tasks.
220 *
221 * The following example explains how to schedule a task that runs every hour.
222 *
223 * ```
224 * $crontab->schedule(new VBOCrontabRunnerAware('unique_id', 60 * 60, function($logger) {
225 * // do stuff
226 * }));
227 * ```
228 *
229 * @param VBOCrontabSimulator $crontab The crontab simulator instance.
230 *
231 * @return void
232 *
233 * @since 1.7
234 */
235 VBOFactory::getPlatform()->getDispatcher()->trigger('onSetupCrontabSimulator', [static::$crontabSimulator]);
236
237 // do not run in case we are doing an AJAX request
238 if (!strcasecmp(JFactory::getApplication()->input->server->get('HTTP_X_REQUESTED_WITH', ''), 'xmlhttprequest')) {
239 static::$crontabSimulator->stop();
240 }
241 }
242
243 return static::$crontabSimulator;
244 }
245 }
246