*/ private array $items; /** * Trail constructor. * * @param array> $items Raw items. */ public function __construct( array $items ) { $normalized = array(); foreach ( $items as $item ) { if ( empty( $item['label'] ) ) { continue; } $label = (string) $item['label']; $url = null; if ( isset( $item['url'] ) && is_scalar( $item['url'] ) ) { $url = (string) $item['url']; } $normalized[] = array( 'label' => $label, 'url' => $url, 'hide_in_schema' => ! empty( $item['hide_in_schema'] ), ); } $this->items = $normalized; } /** * Determine whether the trail contains items. * * @return bool */ public function is_empty(): bool { return empty( $this->items ); } /** * Retrieve all items. * * @return array */ public function items(): array { return $this->items; } /** * Export schema-safe items (excluding hidden entries). * * @return array */ public function to_schema_items(): array { $schema = array(); foreach ( $this->items as $item ) { if ( $item['hide_in_schema'] ) { continue; } $schema[] = array( 'name' => $item['label'], 'url' => $item['url'] ?? '', ); } return $schema; } }