$captureAnyOf At least one of these canonical identifiers. * @param array $settings Required saved values; an `ids` field may cap how many it takes. * @param list $fields Canonical values used by this adapter, not a promise to overwrite Contacts. * @param array $mappedFields * @param list $audienceChannels Channels whose audience this service can receive into, not proof of subscription. */ public function __construct( public readonly array $captureAnyOf = [], public readonly array $settings = [], public readonly array $fields = [], public readonly array $mappedFields = [], public readonly array $audienceChannels = [], ) { } /** @param array $values */ public function acceptsCapture(array $values): bool { foreach ($this->captureAnyOf as $key) { if (self::text($values[$key] ?? null) !== '') return true; } return $this->captureAnyOf === []; } /** @param array $settings * @return list */ public function missingSettings(array $settings): array { $missing = []; foreach ($this->settings as $key => $field) { $ids = $field['type'] === 'ids' ? self::ids($settings[$key] ?? null) : null; // More ids than the service takes is as unready as none: every push would refuse it. if ($ids === null ? self::text($settings[$key] ?? null) === '' : $ids === [] || count($ids) > ($field['max'] ?? PHP_INT_MAX)) { $missing[] = $key; } } return $missing; } /** @param mixed $value */ public static function text($value): string { return is_string($value) ? trim($value) : ''; } /** @param mixed $value * @return list */ public static function ids($value): array { return array_values(array_unique(array_filter(array_map( self::text(...), is_array($value) ? $value : [] ), static fn (string $id): bool => $id !== ''))); } /** @return array */ public function toArray(): array { return ['capture_any_of' => $this->captureAnyOf, 'settings' => $this->settings, 'fields' => $this->fields, 'mapped_fields' => $this->mappedFields, 'audience_channels' => $this->audienceChannels]; } }