| 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 |
* Class constructor. |
| 53 |
* @private This object cannot be instantiated. |
| 54 |
*/ |
| 55 |
private function __construct() |
| 56 |
{ |
| 57 |
// never called |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Class cloner. |
| 62 |
* @private This object cannot be cloned. |
| 63 |
*/ |
| 64 |
private function __clone() |
| 65 |
{ |
| 66 |
// never called |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Returns the current configuration object. |
| 71 |
* |
| 72 |
* @return VBOConfigRegistry |
| 73 |
*/ |
| 74 |
public static function getConfig() |
| 75 |
{ |
| 76 |
// check if config class is already instantiated |
| 77 |
if (is_null(static::$config)) |
| 78 |
{ |
| 79 |
// cache instantiation |
| 80 |
static::$config = new VBOConfigRegistryDatabase([ |
| 81 |
'db' => JFactory::getDbo(), |
| 82 |
]); |
| 83 |
} |
| 84 |
|
| 85 |
return static::$config; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Returns the current platform handler. |
| 90 |
* |
| 91 |
* @return VBOPlatformInterface |
| 92 |
*/ |
| 93 |
public static function getPlatform() |
| 94 |
{ |
| 95 |
// check if platform class is already instantiated |
| 96 |
if (is_null(static::$platform)) |
| 97 |
{ |
| 98 |
if (VBOPlatformDetection::isWordPress()) |
| 99 |
{ |
| 100 |
// running WordPress platform |
| 101 |
static::$platform = new VBOPlatformOrgWordpress(); |
| 102 |
} |
| 103 |
else |
| 104 |
{ |
| 105 |
// running Joomla platform |
| 106 |
static::$platform = new VBOPlatformOrgJoomla(); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
return static::$platform; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Returns the current cron factory. |
| 115 |
* |
| 116 |
* @return VBOCronFactory |
| 117 |
* |
| 118 |
* @since 1.5.10 |
| 119 |
*/ |
| 120 |
public static function getCronFactory() |
| 121 |
{ |
| 122 |
// check if cron factory class is already instantiated |
| 123 |
if (is_null(static::$cronFactory)) |
| 124 |
{ |
| 125 |
// create cron factory class and register the default folder |
| 126 |
static::$cronFactory = new VBOCronFactory; |
| 127 |
static::$cronFactory->setIncludePaths(VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'cronjobs'); |
| 128 |
|
| 129 |
/** |
| 130 |
* Trigger hook to allow third-party plugin to register custom folders in which |
| 131 |
* VikBooking should look for the creation of new cron job instances. |
| 132 |
* |
| 133 |
* In example: |
| 134 |
* $factory->addIncludePath($path); |
| 135 |
* $factory->addIncludePaths([$path1, $path2, ...]); |
| 136 |
* |
| 137 |
* @param VBOCronFactory $factory The cron jobs factory. |
| 138 |
* |
| 139 |
* @return void |
| 140 |
* |
| 141 |
* @since 1.5.10 |
| 142 |
*/ |
| 143 |
VBOFactory::getPlatform()->getDispatcher()->trigger('onCreateCronJobsFactoryVikBooking', [static::$cronFactory]); |
| 144 |
} |
| 145 |
|
| 146 |
return static::$cronFactory; |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Returns the current cron notification center instance. |
| 151 |
* |
| 152 |
* @return VBONotificationCenter |
| 153 |
* |
| 154 |
* @since 1.6.8 |
| 155 |
*/ |
| 156 |
public static function getNotificationCenter() |
| 157 |
{ |
| 158 |
// check if the notification center class is already instantiated |
| 159 |
if (is_null(static::$notificationCenter)) |
| 160 |
{ |
| 161 |
// create Notification Center class |
| 162 |
static::$notificationCenter = new VBONotificationCenter; |
| 163 |
} |
| 164 |
|
| 165 |
return static::$notificationCenter; |
| 166 |
} |
| 167 |
} |
| 168 |
|