Bridge/Symfony/Validator/Constraints/IdentityValidator.php
public function validate($identity, Constraint $constraint)
    {
        if (null === $identity) {
            return;
        }

        if (!$identity instanceof IdentityInterface) {
            throw new UnexpectedTypeException($constraint, IdentityInterface::class);
        }
        if (!$constraint instanceof Identity) {
            throw new UnexpectedTypeException($constraint, Identity::class);
        }

        // All or none
        $gender = $identity->getGender();
        $firstName = $identity->getFirstName();
        $lastName = $identity->getLastName();

        $all = $gender . $lastName . $firstName;

        if (empty($all)) {
            if ($constraint->required) {
                $this->context
                    ->buildViolation($constraint->mandatory)
                    ->atPath('gender')
                    ->addViolation();
            }
        } else {
            $config = [
                'gender'    => [
                    new Assert\NotBlank(['message' => $constraint->gender_is_mandatory]),
                    new Gender(),
                ],
                'firstName' => [
                    new Assert\NotBlank(['message' => $constraint->first_name_is_mandatory]),
                    new Assert\Length(['min' => 2, 'max' => 32,]),
                ],
                'lastName'  => [
                    new Assert\NotBlank(['message' => $constraint->last_name_is_mandatory]),
                    new Assert\Length(['min' => 2, 'max' => 32,]),
                ],
            ];

            if (null === $this->propertyAccessor) {
                $this->propertyAccessor = PropertyAccess::createPropertyAccessor();
            }

            foreach ($config as $field => $constraints) {
                $value = $this->propertyAccessor->getValue($identity, $field);
                $violationList = $this->context->getValidator()->validate($value, $constraints);

                /** @var \Symfony\Component\Validator\ConstraintViolationInterface $violation */
                foreach ($violationList as $violation) {
                    $this->context
                        ->buildViolation($violation->getMessage())
                        ->atPath($field)
                        ->addViolation();
                }
            }
        }
    }
public function validate($identity, Constraint $constraint)
    {
        if (null === $identity) {
            return;
        }

        if (!$identity instanceof IdentityInterface) {
            throw new UnexpectedTypeException($constraint, IdentityInterface::class);
        }
        if (!$constraint instanceof Identity) {
            throw new UnexpectedTypeException($constraint, Identity::class);
        }

        // All or none
        $gender = $identity->getGender();
        $firstName = $identity->getFirstName();
        $lastName = $identity->getLastName();

        $all = $gender . $lastName . $firstName;

        if (empty($all)) {
            if ($constraint->required) {
                $this->context
                    ->buildViolation($constraint->mandatory)
                    ->atPath('gender')
                    ->addViolation();
            }
        } else {
            $config = [
                'gender'    => [
                    new Assert\NotBlank(['message' => $constraint->gender_is_mandatory]),
                    new Gender(),
                ],
                'firstName' => [
                    new Assert\NotBlank(['message' => $constraint->first_name_is_mandatory]),
                    new Assert\Length(['min' => 2, 'max' => 32,]),
                ],
                'lastName'  => [
                    new Assert\NotBlank(['message' => $constraint->last_name_is_mandatory]),
                    new Assert\Length(['min' => 2, 'max' => 32,]),
                ],
            ];

            if (null === $this->propertyAccessor) {
                $this->propertyAccessor = PropertyAccess::createPropertyAccessor();
            }

            foreach ($config as $field => $constraints) {
                $value = $this->propertyAccessor->getValue($identity, $field);
                $violationList = $this->context->getValidator()->validate($value, $constraints);

                /** @var \Symfony\Component\Validator\ConstraintViolationInterface $violation */
                foreach ($violationList as $violation) {
                    $this->context
                        ->buildViolation($violation->getMessage())
                        ->atPath($field)
                        ->addViolation();
                }
            }
        }
    }
public function validate ( $ identity , Constraint $ constraint ) { if ( null === $ identity ) { return ; } if ( ! $ identity instanceof IdentityInterface ) { throw new UnexpectedTypeException ( $ constraint , IdentityInterface :: class ) ; } if ( ! $ constraint instanceof Identity ) { throw new UnexpectedTypeException ( $ constraint , Identity :: class ) ; } // All or none $ gender = $ identity -> getGender ( ) ; $ firstName = $ identity -> getFirstName ( ) ; $ lastName = $ identity -> getLastName ( ) ; $ all = $ gender . $ lastName . $ firstName ; if ( empty ( $ all ) ) { if ( $ constraint -> required ) { $ this -> context -> buildViolation ( $ constraint -> mandatory ) -> atPath ( 'gender' ) -> addViolation ( ) ; } } else { $ config = [ 'gender' => [ new Assert \ NotBlank ( [ 'message' => $ constraint -> gender_is_mandatory ] ) , new Gender ( ) , ] , 'firstName' => [ new Assert \ NotBlank ( [ 'message' => $ constraint -> first_name_is_mandatory ] ) , new Assert \ Length ( [ 'min' => 2 , 'max' => 32 , ] ) , ] , 'lastName' => [ new Assert \ NotBlank ( [ 'message' => $ constraint -> last_name_is_mandatory ] ) , new Assert \ Length ( [ 'min' => 2 , 'max' => 32 , ] ) , ] , ] ; if ( null === $ this -> propertyAccessor ) { $ this -> propertyAccessor = PropertyAccess :: createPropertyAccessor ( ) ; } foreach ( $ config as $ field => $ constraints ) { $ value = $ this -> propertyAccessor -> getValue ( $ identity , $ field ) ; $ violationList = $ this -> context -> getValidator ( ) -> validate ( $ value , $ constraints ) ; /** @var \Symfony\Component\Validator\ConstraintViolationInterface $violation */ foreach ( $ violationList as $ violation ) { $ this -> context -> buildViolation ( $ violation -> getMessage ( ) ) -> atPath ( $ field ) -> addViolation ( ) ; } } } }
{@inheritdoc}
{