<?php

namespace Planaday\Utility\DataFilters;

class AdvancedValidatorFactory {
	/**
	 * @param mixed $data
	 * @param string $name
	 *
	 * @return AdvancedValidator
	 */
	public function getValidator( mixed $data, string $name ):AdvancedValidator {
		return new AdvancedValidator($data, $name);
	}

	public function isEmail( $data ): bool
	{
		if (empty($data)) {
			return true;
		}

		if ( !filter_var( $data, FILTER_VALIDATE_EMAIL ) ) {
			return false;
		}

		return true;
	}

	public function isHexColor( $data ): bool
	{
		if (empty($data)) {
			return true;
		}

		if (is_string($data) && preg_match( '/^#(([a-f0-9]{3}){1,2}|([a-f0-9]{4}){1,2})$/i', $data )) return true;

		return false;
	}
}