| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class Rest_API/Router file. |
| 4 |
* |
| 5 |
* @package PostNLWooCommerce\Rest_API |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types = 1 ); |
| 9 |
|
| 10 |
namespace PostNLWooCommerce\Rest_API; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Class Router |
| 18 |
* |
| 19 |
* Decides per-flow whether the new PostNL SDK is wired up. Every supported |
| 20 |
* flow is gated behind its own filter so flows can be toggled independently |
| 21 |
* during the v4 migration. |
| 22 |
* |
| 23 |
* @package PostNLWooCommerce\Rest_API |
| 24 |
* @since 5.9.6 |
| 25 |
*/ |
| 26 |
class Router { |
| 27 |
|
| 28 |
/** |
| 29 |
* Flows that may be enabled for the PostNL SDK. |
| 30 |
* |
| 31 |
* postcode_check is intentionally absent — it stays on the legacy REST path. |
| 32 |
* |
| 33 |
* @since 5.9.6 |
| 34 |
* @var string[] |
| 35 |
*/ |
| 36 |
const SUPPORTED_FLOWS = array( |
| 37 |
'barcode', |
| 38 |
'timeframe', |
| 39 |
'pickup_location', |
| 40 |
'checkout', |
| 41 |
'label', |
| 42 |
'return_label', |
| 43 |
'letterbox', |
| 44 |
'shipment_and_return', |
| 45 |
'smart_returns', |
| 46 |
); |
| 47 |
|
| 48 |
/** |
| 49 |
* Return whether the SDK is enabled for a given flow. |
| 50 |
* |
| 51 |
* Flows not in SUPPORTED_FLOWS always return false without invoking any filter. |
| 52 |
* Every flow defaults to false; site owners opt in via the filter. |
| 53 |
* |
| 54 |
* @since 5.9.6 |
| 55 |
* |
| 56 |
* @param string $flow Flow identifier. |
| 57 |
* @return bool |
| 58 |
*/ |
| 59 |
public static function sdk_enabled_for( string $flow ): bool { |
| 60 |
if ( ! in_array( $flow, self::SUPPORTED_FLOWS, true ) ) { |
| 61 |
return false; |
| 62 |
} |
| 63 |
|
| 64 |
return (bool) apply_filters( "postnl_sdk_enable_{$flow}", false ); |
| 65 |
} |
| 66 |
} |
| 67 |
|