<?php
/**
 * Registry for local schema-validation rules.
 *
 * @package SEOvaultSEO\Schema\Validation
 */

namespace SEOvaultSEO\Schema\Validation;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Stores rules in deterministic registration order.
 */
class RuleRegistry {

	/**
	 * Registered rules keyed by their stable codes.
	 *
	 * @var RuleInterface[]
	 */
	private $rules = array();

	/**
	 * Add or replace a rule by its stable code.
	 *
	 * @param RuleInterface $rule Rule to register.
	 * @return void
	 */
	public function add( RuleInterface $rule ) {
		$this->rules[ $rule->get_code() ] = $rule;
	}

	/**
	 * Get registered rules in registration order.
	 *
	 * @return RuleInterface[]
	 */
	public function get_all() {
		return array_values( $this->rules );
	}
}
