<?php
/**
 * Block Registery - enregistre les blocs définis par le end user dans un registre centralisé pour une récupération facile
 *
 * @since 2.5.3
 */

namespace EACCustomWidgets\Includes\Blocks\AcfBlockBuilder;

class Block_Registry {
	private static array $blocks = array();

	/**
	 * register
	 *
	 * @param string $block_name
	 * @param array $block_data
	 *
	 * @return void
	 */
	public static function register( string $block_name, array $block_data ): void {
		self::$blocks[ esc_html( $block_name ) ] = self::sanitize_recursive( $block_data );
	}

	private static function sanitize_recursive( $data ) {
		if ( is_array( $data ) ) {
			foreach ( $data as $key => $value ) {
				$data[ $key ] = self::sanitize_recursive( $value );
			}
			return $data;
		}
		return is_scalar( $data ) ? sanitize_text_field( (string) $data ) : $data;
	}

	public static function get_all(): array {
		return self::$blocks;
	}
}
