| 1 |
<?php |
| 2 |
/** |
| 3 |
* Addon License Registry Interface |
| 4 |
* |
| 5 |
* @package Forge12\DoubleOptIn\Licensing |
| 6 |
* @since 4.3.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Forge12\DoubleOptIn\Licensing; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Interface AddonLicenseRegistryInterface |
| 17 |
* |
| 18 |
* @api |
| 19 |
* |
| 20 |
* The license registry is a pure state holder. It does NOT perform license |
| 21 |
* validation — that responsibility belongs to a license provider (e.g. the |
| 22 |
* Pro bundle's LicenseManager). A license provider validates keys against |
| 23 |
* its own server and then calls {@see grant()} on the registry for each |
| 24 |
* addon the license entitles. |
| 25 |
* |
| 26 |
* Addons consume the registry read-only via {@see isLicensed()}. They |
| 27 |
* MUST NOT grant or revoke entitlements themselves — that would defeat |
| 28 |
* the separation of concerns. |
| 29 |
* |
| 30 |
* Free addons do not need to interact with this registry at all; only |
| 31 |
* paid addons gate themselves on {@see isLicensed()}. |
| 32 |
*/ |
| 33 |
interface AddonLicenseRegistryInterface { |
| 34 |
|
| 35 |
/** |
| 36 |
* Grant a license entitlement for an addon. |
| 37 |
* |
| 38 |
* Called by a license provider after successful validation. Idempotent — |
| 39 |
* re-granting the same addon overrides only the source, not the |
| 40 |
* licensed state. |
| 41 |
* |
| 42 |
* @param string $addonId Addon ID, must match {@see \Forge12\DoubleOptIn\Addon\AddonInterface::getId()}. |
| 43 |
* @param string $source Free-form provider identifier for audit logs, |
| 44 |
* e.g. "pro-bundle", "elementor-standalone". Defaults to "default". |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public function grant( string $addonId, string $source = 'default' ): void; |
| 48 |
|
| 49 |
/** |
| 50 |
* Revoke an addon's entitlement. |
| 51 |
* |
| 52 |
* Called when a license expires or is removed. No-op if the addon has |
| 53 |
* no entitlement. |
| 54 |
* |
| 55 |
* @param string $addonId Addon ID. |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
public function revoke( string $addonId ): void; |
| 59 |
|
| 60 |
/** |
| 61 |
* Check whether an addon currently has a valid entitlement. |
| 62 |
* |
| 63 |
* This is the primary method called by paid addons during bootstrap |
| 64 |
* to decide whether to activate their features. |
| 65 |
* |
| 66 |
* @param string $addonId Addon ID. |
| 67 |
* @return bool |
| 68 |
*/ |
| 69 |
public function isLicensed( string $addonId ): bool; |
| 70 |
|
| 71 |
/** |
| 72 |
* Return the source of an addon's entitlement, or null if unlicensed. |
| 73 |
* |
| 74 |
* Useful for debugging and admin UI ("licensed via Pro bundle"). |
| 75 |
* |
| 76 |
* @param string $addonId Addon ID. |
| 77 |
* @return string|null |
| 78 |
*/ |
| 79 |
public function getSource( string $addonId ): ?string; |
| 80 |
|
| 81 |
/** |
| 82 |
* List all addon IDs currently entitled. |
| 83 |
* |
| 84 |
* @return string[] |
| 85 |
*/ |
| 86 |
public function getLicensedAddons(): array; |
| 87 |
} |
| 88 |
|