policyOverride = $policyOverride; $this->exceptionMapperOverride = $exceptionMapperOverride; $this->registrarOverride = $registrarOverride; } /** * Bind every Phase-6 slice-6a REST infrastructure collaborator * into the registry. * * Resolution is eager so a misconfiguration surfaces during * {@see ServiceProviderRegistry::registerAll()} rather than at * the first REST request. * * @param ServiceProviderRegistry $registry Registry driving this * bootstrap pass. */ public function register( ServiceProviderRegistry $registry ): void { $policy = $this->policyOverride ?? new CapabilityPolicy(); $mapper = $this->exceptionMapperOverride ?? new ProviderExceptionMapper(); $registrar = $this->registrarOverride ?? new RouteRegistrar(); $this->resolvedRegistrar = $registrar; $registry->bind( self::BINDING_CAPABILITY_POLICY, $policy ); $registry->bind( self::BINDING_PROVIDER_EXCEPTION_MAPPER, $mapper ); $registry->bind( self::BINDING_ROUTE_REGISTRAR, $registrar ); } /** * Subscribe a `rest_api_init` action callback that drives the * bound {@see RouteRegistrar::register()}. * * The callback is registered as a public method on this provider * (rather than as a closure) so the {@see HookRegistrar}'s * introspection surface carries a stable, named callable that * tests and diagnostics can identify without unwrapping a * closure. * * @param HookRegistrar $hooks Shared hook registrar. */ public function boot( HookRegistrar $hooks ): void { $hooks->addAction( 'rest_api_init', array( $this, 'onRestApiInit' ) ); } /** * `rest_api_init` action callback. * * Drives {@see RouteRegistrar::register()} so every * {@see \Affilun\Presentation\Rest\Routing\RouteDefinition} * appended by subsequent slices' service providers (slice 6b+) * is forwarded to WordPress at the canonical registration * moment. * * Public because {@see HookRegistrar::addAction()} stores the * callable as an `array($this, 'onRestApiInit')` tuple, which * WordPress invokes with public-method visibility. */ public function onRestApiInit(): void { if ( $this->resolvedRegistrar === null ) { return; } $this->resolvedRegistrar->register(); } }