1. Go to this page and download the library: Download jackai/symfony-validator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class DataUniqueValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof DataUnique) {
throw new UnexpectedTypeException($constraint, DataUnique::class);
}
if ($this->checkDataBase($constraint)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ path }}', $path)
->setParameter('{{ string }}', $value)
->addViolation();
}
}
private function checkDataBase(DataUnique $constraint)
{
$ruleOption = $constraint->options;
foreach (['entity', 'rule'] as $k => $v) {
if (!array_key_exists($v, $ruleOption)) {
throw new \RuntimeException("ruleOption.{$v} is
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.