Yoast\WP\SEO\Schema_Aggregator\Domain

Schema_Piece_Collection{}Yoast 1.0

Type-safe collection for Schema_Piece objects.

Хуков нет.

Использование

$Schema_Piece_Collection = new Schema_Piece_Collection();
// use class methods

Методы

  1. public __construct( array $pieces = [] )
  2. public add( Schema_Piece $piece )
  3. public to_array()

Код Schema_Piece_Collection{} Yoast 28.3

class Schema_Piece_Collection {

	/**
	 * The schema pieces.
	 *
	 * @var array<Schema_Piece>
	 */
	private $pieces = [];

	/**
	 * Class constructor.
	 *
	 * @param array<Schema_Piece> $pieces Optional array of Schema_Piece objects.
	 */
	public function __construct( array $pieces = [] ) {
		foreach ( $pieces as $piece ) {
			$this->add( $piece );
		}
	}

	/**
	 * Adds a schema piece to the collection.
	 *
	 * @param Schema_Piece $piece The schema piece to add.
	 *
	 * @return void
	 */
	public function add( Schema_Piece $piece ): void {
		$this->pieces[] = $piece;
	}

	/**
	 * Gets all schema pieces as an array.
	 *
	 * @return array<Schema_Piece> The schema pieces.
	 */
	public function to_array(): array {
		return $this->pieces;
	}
}