| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMailScoped\YayCommerce\AdminShell\License; |
| 4 |
|
| 5 |
use YayMailScoped\YayCommerce\AdminShell\License\Contracts\LicenseConfigAdapter; |
| 6 |
use YayMailScoped\YayCommerce\AdminShell\Registry\PluginLicenseInfo; |
| 7 |
/** |
| 8 |
* Builds a PluginLicenseInfo data object from a LicenseHandler's current state. |
| 9 |
*/ |
| 10 |
class PluginInfoFactory |
| 11 |
{ |
| 12 |
public static function from_adapter(LicenseConfigAdapter $adapter): PluginLicenseInfo |
| 13 |
{ |
| 14 |
$license = new License($adapter); |
| 15 |
$raw_info = $license->get_license_info(); |
| 16 |
$expires_raw = $raw_info['expires'] ?? null; |
| 17 |
$activations_used = (int) ($raw_info['site_count'] ?? 0); |
| 18 |
$activations_limit = (int) ($raw_info['license_limit'] ?? 0); |
| 19 |
$status = 'inactive'; |
| 20 |
if ($license->is_active()) { |
| 21 |
$status = $license->is_expired() ? 'expired' : 'valid'; |
| 22 |
} |
| 23 |
$info = new PluginLicenseInfo(); |
| 24 |
$info->slug = $adapter->get_plugin_slug(); |
| 25 |
$info->name = $adapter->get_plugin_name(); |
| 26 |
$info->version = $adapter->get_plugin_version(); |
| 27 |
$info->basename = $adapter->get_plugin_basename(); |
| 28 |
$info->item_id = $adapter->get_item_id(); |
| 29 |
$info->store_link = $adapter->get_store_link(); |
| 30 |
$info->license_key = (string) $license->get_license_key(); |
| 31 |
$info->status = $status; |
| 32 |
$info->expires_at = $expires_raw && 'Not updated' !== $expires_raw ? $expires_raw : null; |
| 33 |
$info->activations_used = $activations_used; |
| 34 |
$info->activations_limit = $activations_limit; |
| 35 |
$info->is_legacy = \false; |
| 36 |
$info->raw_info = $raw_info; |
| 37 |
return $info; |
| 38 |
} |
| 39 |
} |
| 40 |
|