| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMailScoped\YayCommerce\AdminShell\Registry; |
| 4 |
|
| 5 |
/** |
| 6 |
* Central registry for all plugin license info objects. |
| 7 |
* |
| 8 |
* Plugins call register() during 'yaycommerce_admin_shell_booted' action. |
| 9 |
* The Licenses page calls all() to render the unified list. |
| 10 |
*/ |
| 11 |
class LicenseRegistry |
| 12 |
{ |
| 13 |
/** @var PluginLicenseInfo[] keyed by slug */ |
| 14 |
private array $plugins = []; |
| 15 |
/** |
| 16 |
* Register a plugin's license info. Applies the decoration filter before storing. |
| 17 |
*/ |
| 18 |
public function register($info): void |
| 19 |
{ |
| 20 |
/** @var PluginLicenseInfo $info */ |
| 21 |
$info = apply_filters('yaycommerce_admin_shell_plugin_info', $info, $info->slug); |
| 22 |
$this->plugins[$info->slug] = $info; |
| 23 |
} |
| 24 |
/** |
| 25 |
* Return all registered PluginLicenseInfo objects, keyed by slug. |
| 26 |
* |
| 27 |
* @return PluginLicenseInfo[] |
| 28 |
*/ |
| 29 |
public function all(): array |
| 30 |
{ |
| 31 |
// Refactor old licensing plugin integration |
| 32 |
$old_plugins = []; |
| 33 |
$handlers = ['YayMailScoped\YAYDP\License\License_Handler', 'YayMailScoped\YayMail\License\LicenseHandler', 'YayMailScoped\Yay_Currency\License\LicenseHandler', 'YayMailScoped\Yay_Swatches\License\LicenseHandler', 'YayMailScoped\YayExtra\License\LicenseHandler', 'YayMailScoped\YayRev\License\LicenseHandler', 'YayMailScoped\YayWholesaleB2B\License\LicenseHandler', 'YayMailScoped\YaySMTP\License\LicenseHandler']; |
| 34 |
foreach ($handlers as $handler) { |
| 35 |
if (class_exists($handler) && method_exists($handler, 'get_licensing_plugins')) { |
| 36 |
$plugins = $handler::get_licensing_plugins(); |
| 37 |
if (is_array($plugins)) { |
| 38 |
$old_plugins = array_merge($old_plugins, $plugins); |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
return array_merge($this->plugins, $old_plugins); |
| 43 |
} |
| 44 |
/** |
| 45 |
* Return a single PluginLicenseInfo by slug, or null if not registered. |
| 46 |
*/ |
| 47 |
public function get(string $slug): ?PluginLicenseInfo |
| 48 |
{ |
| 49 |
return $this->plugins[$slug] ?? null; |
| 50 |
} |
| 51 |
/** |
| 52 |
* Check if a slug is registered. |
| 53 |
*/ |
| 54 |
public function has(string $slug): bool |
| 55 |
{ |
| 56 |
return isset($this->plugins[$slug]); |
| 57 |
} |
| 58 |
} |
| 59 |
|