*/ private $adapters = array(); /** @var array */ private $globals = array(); /** @var bool */ private $hookFired = false; public function register( FollowUpAdapterInterface $adapter ): void { if ( $adapter instanceof GlobalFollowUpAdapterInterface ) { $this->globals[ $adapter->getIntegration() ] = $adapter; return; } $this->adapters[ $adapter->getIntegration() ] = $adapter; } /** * Form or global adapter by the integration stored on a row. */ public function get( string $integration ): ?FollowUpAdapterInterface { $this->fireHookOnce(); return $this->adapters[ $integration ] ?? $this->globals[ $integration ] ?? null; } /** * Adapters that follow up every opt-in (since 5.8.0). * * @return array */ public function globals(): array { $this->fireHookOnce(); return $this->globals; } /** * Find the adapter responsible for an opt-in. * * `OptIn::isType()` is a lookup per call (post type / post meta), so * each registered integration is asked at most once. */ public function forOptIn( OptIn $optIn ): ?FollowUpAdapterInterface { $this->fireHookOnce(); foreach ( $this->adapters as $integration => $adapter ) { if ( $optIn->isType( $integration ) ) { return $adapter; } } return null; } /** * @return string[] */ public function integrations(): array { $this->fireHookOnce(); return array_keys( $this->adapters ); } private function fireHookOnce(): void { if ( $this->hookFired ) { return; } $this->hookFired = true; if ( function_exists( 'do_action' ) ) { /** * Register additional follow-up adapters. * * @param FollowUpAdapterRegistry $registry * * @since 5.6.0 */ do_action( 'f12_doi_register_follow_up_adapters', $this ); } } }