| 1 |
<?php |
| 2 |
/** |
| 3 |
* Conditional bootstrap for the NotificationX MCP module. |
| 4 |
* |
| 5 |
* NotificationX still supports PHP 5.6, but the MCP server uses modern PHP |
| 6 |
* (random_bytes, hash_equals, JSON everywhere). Rather than raise the plugin's |
| 7 |
* floor for everyone, the MCP module is a progressive enhancement: it loads |
| 8 |
* only when the runtime can support it. On older PHP the plugin behaves exactly |
| 9 |
* as before and MCP simply does not appear. |
| 10 |
* |
| 11 |
* @package NotificationX\MCP |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace NotificationX\MCP; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Static entry point invoked from the main NotificationX engine. |
| 22 |
*/ |
| 23 |
class Bootstrap { |
| 24 |
|
| 25 |
/** |
| 26 |
* Minimum PHP version the MCP module requires. |
| 27 |
*/ |
| 28 |
const MIN_PHP = '7.0'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Load the MCP module when the runtime supports it. |
| 32 |
* |
| 33 |
* @return void |
| 34 |
*/ |
| 35 |
public static function init() { |
| 36 |
if ( ! self::is_supported() ) { |
| 37 |
return; |
| 38 |
} |
| 39 |
Manager::get_instance()->init(); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Whether the current runtime can run the MCP module. |
| 44 |
* |
| 45 |
* @return bool |
| 46 |
*/ |
| 47 |
public static function is_supported() { |
| 48 |
$supported = version_compare( PHP_VERSION, self::MIN_PHP, '>=' ) |
| 49 |
&& function_exists( 'random_bytes' ) |
| 50 |
&& function_exists( 'hash_equals' ); |
| 51 |
|
| 52 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Prefixed with nx_ per NotificationX convention. |
| 53 |
return (bool) apply_filters( 'nx_mcp_is_supported', $supported ); |
| 54 |
} |
| 55 |
} |
| 56 |
|