<commit_before><?php
/*************************************************
 * Titan-2 Mini Framework
 * Form Validation Library
 *
 * Author   : <NAME>
 * Web      : http://www.titanphp.com
 * Docs     : http://kilavuz.titanphp.com 
 * Github   : http://github.com/tkaratug/titan2
 * License  : MIT   
 *
 *************************************************/
namespace System\Libs\Validation;

class Validation
{
	// Validation errors
	protected $errors 	= [];

	// Label for fields
	protected $labels	= [];

	// Validation rules
	protected $rules 	= [];

	// Data to validate
	protected $data		= [];

	/**
	 * Define Validation Rules
	 *
	 * @param array $rules
	 * @return void
	 */
	public function rules($rules)
	{
		foreach ($rules as $key => $value) {	
			$this->labels[$value['field']] 	= $value['label'];
			$this->rules[$value['field']]	= $value['rules'];
		}
	}

	/**
	 * Define One Validation Rule
	 *
	 * @param string $field
	 * @param string $label
	 * @param string $rules
	 * @return void
	 */
	public function rule($field, $label, $rules)
	{
		$this->labels[$field] 	= $label;
		$this->rules[$field]	= $rules;
	}

	/**
	 * Define Bulk Data to Validate
	 *
	 * @param array $data
	 * @return void
	 */
	public function bulkData($data)
	{
		foreach ($data as $key => $value) {
			$this->data[$value['field']] = $value['data'];
		}
	}

	/**
	 * Define Data to Validate
	 *
	 * @param string $field
	 * @param string $data
	 * @return void
	 */
	public function data($field, $data)
	{
		$this->data[$field] = $data;
	}

	/**
	 * Validate
	 *
	 * @return boolean
	 */
	public function isValid()
	{
		foreach ($this->rules as $key => $value) {
			
			$rules = explode('|', $value);

			foreach ($rules as $rule) {
				if (strpos($rule, ',')) {
					$group  = explode(',', $rule);
					$filter = $group[0];
                    $params = $group[1];

                    if ($filter == 'matches') {
                    	if ($this->matches($this->data[$key], $this->data[$params]) === false)
                    		$this->errors[] = lang('validation', $filter . '_error', ['%s' => $this->labels[$key], '%t' => $params]);
                    } else {
                    	if ($this->$filter($this->data[$key], $params) === false)
                            $this->errors[] = lang('validation', $filter . '_error', ['%s' => $this->labels[$key], '%t' => $params]);<commit_msg>Bug fixed in Validation library<commit_after><?php
/*************************************************
 * Titan-2 Mini Framework
 * Form Validation Library
 *
 * Author   : <NAME>
 * Web      : http://www.titanphp.com
 * Docs     : http://kilavuz.titanphp.com 
 * Github   : http://github.com/tkaratug/titan2
 * License  : MIT   
 *
 *************************************************/
namespace System\Libs\Validation;

class Validation
{
	// Validation errors
	protected $errors 	= [];

	// Label for fields
	protected $labels	= [];

	// Validation rules
	protected $rules 	= [];

	// Data to validate
	protected $data		= [];

	/**
	 * Define Validation Rules
	 *
	 * @param array $rules
	 * @return void
	 */
	public function rules($rules)
	{
		foreach ($rules as $key => $value) {	
			$this->labels[$value['field']] 	= $value['label'];
			$this->rules[$value['field']]	= $value['rules'];
		}
	}

	/**
	 * Define One Validation Rule
	 *
	 * @param string $field
	 * @param string $label
	 * @param string $rules
	 * @return void
	 */
	public function rule($field, $label, $rules)
	{
		$this->labels[$field] 	= $label;
		$this->rules[$field]	= $rules;
	}

	/**
	 * Define Bulk Data to Validate
	 *
	 * @param array $data
	 * @return void
	 */
	public function bulkData($data)
	{
		foreach ($data as $key => $value) {
			$this->data[$value['field']] = $value['data'];
		}
	}

	/**
	 * Define Data to Validate
	 *
	 * @param string $field
	 * @param string $data
	 * @return void
	 */
	public function data($field, $data)
	{
		$this->data[$field] = $data;
	}

	/**
	 * Validate
	 *
	 * @return boolean
	 */
	public function isValid()
	{
		foreach ($this->rules as $key => $value) {
			
			$rules = explode('|', $value);

			foreach ($rules as $rule) {
				if (strpos($rule, ',')) {
					$group  = explode(',', $rule);
					$filter = $group[0];
                    $params = $group[1];

                    if ($filter == 'matches') {
                    	if ($this->matches($this->data[$key], $this->data[$params]) === false)
                    		$this->errors[] = lang('validation', $filter . '_error', ['%s' => $this->labels[$key], '%t' => $this->labels[$params]]);
                    } else {
                    	if ($this->$filter($this->data[$key], $params) === false)
                            $this->errors[] = lang('validation', $filter . '_error', ['%s' => $this->labels[$key], '%t' => $this->labels[$params]]);
{'fraction_non_alphanumeric': 0.22884535223009586, 'fraction_numerical': 0.0016673614005835765, 'mean_word_length': 2.6055597295266715, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4024949', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1502, 'n_words': 355}