| 1 |
<?php |
| 2 |
/** |
| 3 |
* License: Service provider |
| 4 |
* |
| 5 |
* @package SimplePay |
| 6 |
* @subpackage Core |
| 7 |
* @copyright Copyright (c) 2022, Sandhills Development, LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 4.4.1 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace SimplePay\Core\License; |
| 13 |
|
| 14 |
use SimplePay\Core\AbstractPluginServiceProvider; |
| 15 |
use SimplePay\Vendor\League\Container\ServiceProvider\BootableServiceProviderInterface; |
| 16 |
|
| 17 |
/** |
| 18 |
* LicenseServiceProvider class. |
| 19 |
* |
| 20 |
* @since 4.4.1 |
| 21 |
*/ |
| 22 |
class LicenseServiceProvider extends AbstractPluginServiceProvider implements BootableServiceProviderInterface { |
| 23 |
|
| 24 |
/** |
| 25 |
* {@inheritdoc} |
| 26 |
*/ |
| 27 |
public function get_services() { |
| 28 |
return array( |
| 29 |
'license', |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* {@inheritdoc} |
| 35 |
*/ |
| 36 |
public function get_subscribers() { |
| 37 |
return array( |
| 38 |
'license-validator-subscriber', |
| 39 |
'license-management-subscriber', |
| 40 |
'license-setting-susbcriber', |
| 41 |
'license-notification-subscriber', |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* {@inheritdoc} |
| 47 |
*/ |
| 48 |
public function boot() { |
| 49 |
$container = $this->getContainer(); |
| 50 |
|
| 51 |
// License. |
| 52 |
$container->share( 'license', License::class ) |
| 53 |
->withArgument( $this->get_license_key() ); |
| 54 |
|
| 55 |
$inflector = $container->inflector( LicenseAwareInterface::class ); |
| 56 |
|
| 57 |
if ( $inflector instanceof \SimplePay\Vendor\League\Container\Inflector\Inflector ) { |
| 58 |
$inflector->invokeMethod( |
| 59 |
'set_license', |
| 60 |
array( $this->container->get( 'license' ) ) |
| 61 |
); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* {@inheritdoc} |
| 67 |
*/ |
| 68 |
public function register() { |
| 69 |
$container = $this->getContainer(); |
| 70 |
|
| 71 |
// Activate/deactivate helper. |
| 72 |
$container->share( 'license-manager', LicenseManager::class ); |
| 73 |
|
| 74 |
// Daily license check. |
| 75 |
$container->share( |
| 76 |
'license-validator-subscriber', |
| 77 |
LicenseValidatorSubscriber::class |
| 78 |
) |
| 79 |
->withArgument( $container->get( 'license-manager' ) ) |
| 80 |
->withArgument( $container->get( 'scheduler' ) ); |
| 81 |
|
| 82 |
// AJAX activate/deactivate subscriber. |
| 83 |
$container->share( |
| 84 |
'license-management-subscriber', |
| 85 |
LicenseManagementSubscriber::class |
| 86 |
) |
| 87 |
->withArgument( $container->get( 'license-manager' ) ); |
| 88 |
|
| 89 |
// Setting UI subscriber. |
| 90 |
$container->share( |
| 91 |
'license-setting-susbcriber', |
| 92 |
LicenseSettingSubscriber::class |
| 93 |
); |
| 94 |
|
| 95 |
// Notification inbox subscriber. |
| 96 |
$container->share( |
| 97 |
'license-notification-subscriber', |
| 98 |
LicenseNotificationSubscriber::class |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Returns the install's license key; set via constant or option. |
| 104 |
* |
| 105 |
* @since 4.4.1 |
| 106 |
* |
| 107 |
* @return string |
| 108 |
*/ |
| 109 |
private function get_license_key() { |
| 110 |
if ( true === defined( 'SIMPLE_PAY_LICENSE_KEY' ) ) { |
| 111 |
$key = SIMPLE_PAY_LICENSE_KEY; |
| 112 |
} else { |
| 113 |
$key = get_option( 'simpay_license_key', '' ); |
| 114 |
} |
| 115 |
|
| 116 |
/** @var string $key */ |
| 117 |
return trim( $key ); |
| 118 |
} |
| 119 |
|
| 120 |
} |
| 121 |
|