<?php
/**
 * Element-type extension registry.
 *
 * @package EntryFoundry
 */

namespace EntryFoundry\Core\Services\Extension;

// phpcs:disable Squiz.Commenting, Generic.Commenting.DocComment

final class ElementTypeRegistry {
	/** @var array<string, callable|null> */
	private $types = array();

	public function register( string $type, callable $renderer = null ): void {
		$this->types[ preg_replace( '/[^a-z0-9_-]/', '', strtolower( $type ) ) ] = $renderer;
	}

	public function has( string $type ): bool {
		return array_key_exists( $type, $this->types );
	}

	/** @return string[] */
	public function all(): array {
		return array_keys( $this->types );
	}
}
