| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMailScoped\YayCommerce\AdminShell\Registry; |
| 4 |
|
| 5 |
/** |
| 6 |
* Frozen data contract for a registered plugin's license state. |
| 7 |
* |
| 8 |
* APPEND-ONLY — existing public properties must never be renamed or removed. |
| 9 |
* New properties may be added in MINOR versions; removing/renaming requires MAJOR bump. |
| 10 |
*/ |
| 11 |
final class PluginLicenseInfo |
| 12 |
{ |
| 13 |
/** Plugin slug — byte-exact wp_options prefix. */ |
| 14 |
public string $slug = ''; |
| 15 |
/** Human-readable display name. */ |
| 16 |
public string $name = ''; |
| 17 |
/** Plugin version string. */ |
| 18 |
public string $version = ''; |
| 19 |
/** WP plugin basename, e.g. 'yaymail-pro/yaymail.php'. */ |
| 20 |
public string $basename = ''; |
| 21 |
/** EDD download ID. */ |
| 22 |
public int $item_id = 0; |
| 23 |
/** Product page URL. */ |
| 24 |
public string $store_link = ''; |
| 25 |
/** |
| 26 |
* License key (raw). Redacted when serialized via toArray(). |
| 27 |
* Never log or expose this field directly. |
| 28 |
*/ |
| 29 |
public string $license_key = ''; |
| 30 |
/** |
| 31 |
* License status: 'valid'|'invalid'|'expired'|'inactive'|'disabled'|'unknown' |
| 32 |
*/ |
| 33 |
public string $status = 'unknown'; |
| 34 |
/** Expiry in ISO 8601 format, 'lifetime', or null if not retrieved. */ |
| 35 |
public ?string $expires_at = null; |
| 36 |
/** Number of activations used. */ |
| 37 |
public int $activations_used = 0; |
| 38 |
/** Maximum activations allowed (0 = unlimited). */ |
| 39 |
public int $activations_limit = 0; |
| 40 |
/** True when sourced via LegacyBridge (yaycommerce_licensing_plugins filter). */ |
| 41 |
public bool $is_legacy = \false; |
| 42 |
/** Raw EDD response blob for debugging. Never expose to end-users. */ |
| 43 |
public array $raw_info = []; |
| 44 |
/** |
| 45 |
* Return array representation suitable for passing to JS/REST. |
| 46 |
* Redacts license_key to first 8 chars + asterisks. |
| 47 |
*/ |
| 48 |
public function toArray() : array |
| 49 |
{ |
| 50 |
$key_display = ''; |
| 51 |
if (!empty($this->license_key)) { |
| 52 |
$visible = \substr($this->license_key, 0, 8); |
| 53 |
$hidden_len = \max(0, \strlen($this->license_key) - 8); |
| 54 |
$key_display = $visible . \str_repeat('*', \min($hidden_len, 20)); |
| 55 |
} |
| 56 |
return [ |
| 57 |
'slug' => $this->slug, |
| 58 |
'name' => $this->name, |
| 59 |
'version' => $this->version, |
| 60 |
'basename' => $this->basename, |
| 61 |
'item_id' => $this->item_id, |
| 62 |
'store_link' => $this->store_link, |
| 63 |
'license_key' => $key_display, |
| 64 |
// redacted |
| 65 |
'status' => $this->status, |
| 66 |
'expires_at' => $this->expires_at, |
| 67 |
'activations_used' => $this->activations_used, |
| 68 |
'activations_limit' => $this->activations_limit, |
| 69 |
'is_legacy' => $this->is_legacy, |
| 70 |
]; |
| 71 |
} |
| 72 |
} |
| 73 |
|