Lite
2 months ago
ApplicationService.php
1 month ago
DataModifier.php
1 month ago
DomainService.php
1 month ago
EventListener.php
1 month ago
InfrastructureService.php
1 month ago
Licence.php
2 weeks ago
LicenceConstants.php
6 months ago
DomainService.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Infrastructure\Licence; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Services\Settings\SettingsService; |
| 6 | use AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage; |
| 7 | |
| 8 | /** |
| 9 | * Class DomainService |
| 10 | * |
| 11 | * @package AmeliaBooking\Infrastructure\Licence |
| 12 | */ |
| 13 | class DomainService extends Lite\DomainService |
| 14 | { |
| 15 | /** |
| 16 | * Map of license names to their corresponding class names |
| 17 | */ |
| 18 | private static $licenseClassMap = [ |
| 19 | LicenceConstants::LITE => 'AmeliaBooking\Infrastructure\Licence\Lite\DomainService', |
| 20 | LicenceConstants::STARTER => 'AmeliaBooking\Infrastructure\Licence\Lite\DomainService', |
| 21 | LicenceConstants::BASIC => 'AmeliaBooking\Infrastructure\Licence\Lite\DomainService', |
| 22 | LicenceConstants::PRO => 'AmeliaBooking\Infrastructure\Licence\Lite\DomainService', |
| 23 | LicenceConstants::DEVELOPER => 'AmeliaBooking\Infrastructure\Licence\Lite\DomainService', |
| 24 | ]; |
| 25 | |
| 26 | /** |
| 27 | * Get the appropriate license class based on settings (only in development mode) |
| 28 | * |
| 29 | * @return string The fully qualified class name of the license |
| 30 | */ |
| 31 | private static function getLicenseClass() |
| 32 | { |
| 33 | // In production, always use the parent class (Lite) |
| 34 | if (!AMELIA_DEV) { |
| 35 | return 'AmeliaBooking\Infrastructure\Licence\Lite\DomainService'; |
| 36 | } |
| 37 | |
| 38 | // In development, get the license from settings |
| 39 | $settingsService = new SettingsService(new SettingsStorage()); |
| 40 | $currentLicense = $settingsService->getSetting('activation', 'licence'); |
| 41 | $currentLicense = !empty($currentLicense) ? $currentLicense : LicenceConstants::DEVELOPER; |
| 42 | |
| 43 | // Return the appropriate license class |
| 44 | return self::$licenseClassMap[$currentLicense] ?? 'AmeliaBooking\Infrastructure\Licence\Lite\DomainService'; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Delegate static method calls to the appropriate license class in development mode |
| 49 | * |
| 50 | * @param string $method |
| 51 | * @param array $arguments |
| 52 | * @return mixed |
| 53 | */ |
| 54 | public static function __callStatic($method, $arguments) |
| 55 | { |
| 56 | // In production, use normal inheritance (class extends were changed by build scripts) |
| 57 | if (!AMELIA_DEV) { |
| 58 | return call_user_func_array(['parent', $method], $arguments); |
| 59 | } |
| 60 | |
| 61 | // In development, dynamically load the appropriate license class |
| 62 | $licenseClass = self::getLicenseClass(); |
| 63 | return call_user_func_array([$licenseClass, $method], $arguments); |
| 64 | } |
| 65 | } |
| 66 |