*/ private array $tabs; /** @var array */ private array $settings = array(); /** @var array */ private array $fields = array(); /** * @param list $providers Tab definition providers. * @throws \InvalidArgumentException When identifiers are duplicated. */ public function __construct( array $providers ) { $this->tabs = array(); $tab_ids = array(); $section_ids = array(); foreach ( $providers as $provider ) { $tab = $provider->definition(); $this->assert_unique( $tab->slug, $tab_ids ); $tab_ids[] = $tab->slug; $this->tabs[] = $tab; foreach ( $tab->sections as $section ) { $this->assert_unique( $section->id, $section_ids ); $section_ids[] = $section->id; foreach ( $section->fields as $field ) { if ( isset( $this->fields[ $field->id ] ) ) { throw new \InvalidArgumentException( 'Duplicate settings field definition.' ); } $this->fields[ $field->id ] = $field; foreach ( $field->settings as $setting ) { if ( isset( $this->settings[ $setting->option_name ] ) ) { throw new \InvalidArgumentException( 'Duplicate setting definition.' ); } $this->settings[ $setting->option_name ] = $setting; } } } } } public static function create_default(): self { return new self( array( new GeneralTab(), new AnalyticsTab(), new AppearanceTab(), new SecurityTab(), new AntiSpamTab(), new PerformanceTab(), new ContentTypesTab(), new SupportTab(), new WooCommerceTab(), new MiscTab(), ) ); } /** @return list */ public function tabs(): array { return $this->tabs; } /** @return list */ public function available_tabs(): array { return \array_values( \array_filter( $this->tabs, static fn ( TabDefinition $tab ): bool => $tab->requirement->satisfied() ) ); } /** @return array */ public function settings(): array { return $this->settings; } /** @return array */ public function fields(): array { return $this->fields; } public function setting( string $option_name ): ?SettingDefinition { return $this->settings[ $option_name ] ?? null; } public function field( string $field_id ): ?FieldDefinition { return $this->fields[ $field_id ] ?? null; } /** @return array */ public function public_tokens(): array { return PublicTokenRegistry::all(); } /** * @param list $ids Existing identifiers. * @throws \InvalidArgumentException When the identifier already exists. */ private function assert_unique( string $id, array $ids ): void { if ( \in_array( $id, $ids, true ) ) { throw new \InvalidArgumentException( 'Duplicate settings definition.' ); } } }