POSController.php
78 lines
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Automattic\WooCommerce\Internal\POS; |
| 5 | |
| 6 | defined( 'ABSPATH' ) || exit; |
| 7 | |
| 8 | use Automattic\WooCommerce\Internal\Features\FeaturesController; |
| 9 | use Automattic\WooCommerce\Internal\RegisterHooksInterface; |
| 10 | |
| 11 | /** |
| 12 | * Feature orchestrator for the POS staff + attribution iteration. |
| 13 | * |
| 14 | * Gates the feature on the dev-only `point_of_sale_staff` flag. The runtime surfaces — |
| 15 | * staff REST endpoint, order/coupon attribution hooks, and the wp-admin Staff UI — |
| 16 | * register themselves here as they are added in follow-up changes; until then on_init() |
| 17 | * is an intentional no-op even when the flag is on. |
| 18 | * |
| 19 | * @since 11.0.0 |
| 20 | * @internal |
| 21 | */ |
| 22 | class POSController implements RegisterHooksInterface { |
| 23 | |
| 24 | private const FEATURE_FLAG = 'point_of_sale_staff'; |
| 25 | |
| 26 | /** |
| 27 | * Features controller used to gate hook registration on the POS feature flags. |
| 28 | * |
| 29 | * @var FeaturesController |
| 30 | */ |
| 31 | private FeaturesController $features_controller; |
| 32 | |
| 33 | /** |
| 34 | * Initialize dependencies via the DI container. |
| 35 | * |
| 36 | * @internal |
| 37 | * |
| 38 | * @param FeaturesController $features_controller The features controller. |
| 39 | */ |
| 40 | final public function init( FeaturesController $features_controller ): void { |
| 41 | $this->features_controller = $features_controller; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Register the feature surface. |
| 46 | * |
| 47 | * The feature-flag check is deferred to `on_init` because `feature_is_enabled()` |
| 48 | * walks `FeaturesController::init_feature_definitions()`, which contains |
| 49 | * `__( ..., 'woocommerce' )` calls. Evaluating those before `init` triggers |
| 50 | * WP 6.7's "translation loading … too early" notice (and the headers-already-sent |
| 51 | * cascade that follows). |
| 52 | * |
| 53 | * @since 11.0.0 |
| 54 | */ |
| 55 | public function register(): void { |
| 56 | add_action( 'init', array( $this, 'on_init' ) ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Wire up the feature surface once translations are safe to load. |
| 61 | * |
| 62 | * No-op when the gating flag is off. Runtime surfaces are registered here |
| 63 | * as they are added in follow-up changes. |
| 64 | * |
| 65 | * @internal |
| 66 | * |
| 67 | * @since 11.0.0 |
| 68 | */ |
| 69 | public function on_init(): void { |
| 70 | if ( ! $this->features_controller->feature_is_enabled( self::FEATURE_FLAG ) ) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | // Runtime surfaces (staff REST endpoint, attribution hooks, admin Staff UI) |
| 75 | // register here as they are added in follow-up changes. |
| 76 | } |
| 77 | } |
| 78 |