<commit_before><?php
namespace WFV;
defined( 'ABSPATH' ) or die();

use WFV\Abstraction\Composable;
use WFV\Contract\ValidationInterface;

/**
 * Form Composition
 *
 * @since 0.10.0
 */
class FormComposite extends Composable {

	/**
	 *
	 *
	 * @since 0.10.0
	 *
	 * @param string $alias
	 * @param array $collected
	 * @param ValidationInterface $adapter
	 */
	function __construct( $alias, array $collected = [], ValidationInterface $adapter ) {
		$this->alias = $alias;
		$this->install( $collected );
		$this->adapter = $adapter;
	}

	/**
	 * Convenience method to repopulate checkbox input
	 *
	 * @since 0.10.0
	 *
	 * @param string $field Field name.
	 * @param string $value Value to compare against.
	 * @return string|null
	 */
	public function checked_if( $field = null, $value = null ) {
		return $this->string_or_null( 'checked', $field, $value );
	}

	/**
	 * Activate validator with the rules and messages
	 *  via adapter
	 *
	 * @since 0.10.0
	 *
	 * @param string $rule
	 * @param string $field
	 */
	public function constrain() {
		$rules = $this->utilize('rules');
		$messages = $this->utilize('messages');

		$this->adapter('validator')
			->constrain( $rules, $messages );
		return $this;
	}

	/**
	 * Use error collection
	 *
	 * @since 0.10.0
	 *
	 * @return WFV\Component\ErrorCollection
	 */
	public function errors() {
		$errors = $this->adapter('validator')->errors();
		return $this->utilize('errors')
			->set_errors( $errors );
	}

	/**
	 * Use input collection
	 *
	 * @since 0.10.0
	 *
	 * @return WFV\Component\InputCollection
	 */
	public function input() {
		return $this->utilize('input');
	}

	/**
	 * Use message collection
	 *
	 * @since 0.10.0
	 *
	 * @return WFV\Component\InputCollection
	 */
	public function messages() {
		return $this->utilize('messages');
	}

	/**
	 * Convenience method to repopulate select input
	 *
	 * @since 0.10.0
	 *
	 * @param string $field Field name.
	 * @param string $value Value to compare against.
	 * @return string|null
	 */
	public function selected_if( $field = null, $value = null ) {
		return $this->string_or_null( 'selected', $field, $value );
	}

	/**
	 * Validate the input
	 *
	 * @since 0.10.0
	 *
	 * @return bool
	 */
	public function validate() {
		$is_valid = $this->adapter('validator')->validate();

		if ( false === $is_valid ) {<commit_msg>FormComposite - bringing back method to render hidden form fields<commit_after><?php
namespace WFV;
defined( 'ABSPATH' ) or die();

use WFV\Abstraction\Composable;
use WFV\Contract\ValidationInterface;

/**
 * Form Composition
 *
 * @since 0.10.0
 */
class FormComposite extends Composable {

	/**
	 *
	 *
	 * @since 0.10.0
	 *
	 * @param string $alias
	 * @param array $collected
	 * @param ValidationInterface $adapter
	 */
	function __construct( $alias, array $collected = [], ValidationInterface $adapter ) {
		$this->alias = $alias;
		$this->install( $collected );
		$this->adapter = $adapter;
	}

	/**
	 * Convenience method to repopulate checkbox input
	 *
	 * @since 0.10.0
	 *
	 * @param string $field Field name.
	 * @param string $value Value to compare against.
	 * @return string|null
	 */
	public function checked_if( $field = null, $value = null ) {
		return $this->string_or_null( 'checked', $field, $value );
	}

	/**
	 * Activate validator with the rules and messages
	 *  via adapter
	 *
	 * @since 0.10.0
	 *
	 * @param string $rule
	 * @param string $field
	 */
	public function constrain() {
		$rules = $this->utilize('rules');
		$messages = $this->utilize('messages');

		$this->adapter('validator')
			->constrain( $rules, $messages );
		return $this;
	}

	/**
	 * Use error collection
	 *
	 * @since 0.10.0
	 *
	 * @return WFV\Component\ErrorCollection
	 */
	public function errors() {
		$errors = $this->adapter('validator')->errors();
		return $this->utilize('errors')
			->set_errors( $errors );
	}

	/**
	 * Use input collection
	 *
	 * @since 0.10.0
	 *
	 * @return WFV\Component\InputCollection
	 */
	public function input() {
		return $this->utilize('input');
	}

	/**
	 * Use message collection
	 *
	 * @since 0.10.0
	 *
	 * @return WFV\Component\InputCollection
	 */
	public function messages() {
		return $this->utilize('messages');
	}

	/**
	 *
	 *
	 * @since 0.10.0
	 *
	 */
	public function render_token_field() {
    // TODO - Move markup into a view
		$token_name = $this->alias . '_token';
		echo $nonce_field = wp_nonce_field( $this->alias, $token_name, false, false );
		echo $action_field = '<input type="hidden" name="action" value="'. $this->alias .'">';
	}

	/**
	 * Convenience method to repopulate select input
	 *
	 * @since 0.10.0
	 *
	 * @param string $field Field name.
	 * @param string $value Value to compare against.
	 * @return string|null
	 */
	public function selected_if( $field = null, $value = null ) {
		return $this->string_or_null( 'selected', $field, $value );
	}

	/**
	 * Validate the input
	 *
	 * @since 0.10.0
	 *
	 * @return bool
	 */
	public function validate() {
		$is_valid = $this->adapter('validator')->validate();

		if ( false === $is_valid ) {
{'fraction_non_alphanumeric': 0.15958917637764172, 'fraction_numerical': 0.015010863124629667, 'mean_word_length': 3.1782178217821784, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2092340', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1626, 'n_words': 428}