public function validate($basket, Constraint $constraint)
    {
        foreach ($basket->getBasketElements() as $pos => $basketElement) {
            // create a new ErrorElement object
            $errorElement = new ErrorElement(
                $basket,
                $this->constraintValidatorFactory,
                $this->context,
                $this->context->getGroup()
            );

            $errorElement->with('basketElements['.$pos.']');

            // validate the basket element through the related service provider
            $this->productPool
                ->getProvider($basketElement->getProductCode())
                ->validateFormBasketElement($errorElement, $basketElement, $basket);
        }

        if (\count($this->context->getViolations()) > 0) {
            $this->context->addViolationAt('basketElements', $constraint->message);
        }
    }
public function validate($basket, Constraint $constraint)
    {
        foreach ($basket->getBasketElements() as $pos => $basketElement) {
            // create a new ErrorElement object
            $errorElement = new ErrorElement(
                $basket,
                $this->constraintValidatorFactory,
                $this->context,
                $this->context->getGroup()
            );

            $errorElement->with('basketElements['.$pos.']');

            // validate the basket element through the related service provider
            $this->productPool
                ->getProvider($basketElement->getProductCode())
                ->validateFormBasketElement($errorElement, $basketElement, $basket);
        }

        if (\count($this->context->getViolations()) > 0) {
            $this->context->addViolationAt('basketElements', $constraint->message);
        }
    }
public function validate ( $ basket , Constraint $ constraint ) { foreach ( $ basket -> getBasketElements ( ) as $ pos => $ basketElement ) { // create a new ErrorElement object $ errorElement = new ErrorElement ( $ basket , $ this -> constraintValidatorFactory , $ this -> context , $ this -> context -> getGroup ( ) ) ; $ errorElement -> with ( 'basketElements[' . $ pos . ']' ) ; // validate the basket element through the related service provider $ this -> productPool -> getProvider ( $ basketElement -> getProductCode ( ) ) -> validateFormBasketElement ( $ errorElement , $ basketElement , $ basket ) ; } if ( \ count ( $ this -> context -> getViolations ( ) ) > 0 ) { $ this -> context -> addViolationAt ( 'basketElements' , $ constraint -> message ) ; } }
The validator asks each product repository to validate the related basket element.

@param BasketInterface $basket
@param Constraint      $constraint
The validator asks each product repository to validate the related basket element .