public function preValidate(array $writeCommands, WriteContext $context): void
    {
        $violationList = new ConstraintViolationList();

        /** @var WriteCommandInterface $command */
        foreach ($writeCommands as $command) {
            if (!$command instanceof InsertCommand && !$command instanceof UpdateCommand) {
                continue;
            }

            switch (get_class($command->getDefinition())) {
                case PromotionDefinition::class:
                    $this->validatePromotion($command->getPayload(), $violationList);
                    break;

                case PromotionDiscountDefinition::class:
                    $this->validateDiscount($command->getPayload(), $violationList);
                    break;
            }
        }

        if ($violationList->count() > 0) {
            throw new WriteConstraintViolationException($violationList);
        }
    }
public function preValidate(array $writeCommands, WriteContext $context): void
    {
        $violationList = new ConstraintViolationList();

        /** @var WriteCommandInterface $command */
        foreach ($writeCommands as $command) {
            if (!$command instanceof InsertCommand && !$command instanceof UpdateCommand) {
                continue;
            }

            switch (get_class($command->getDefinition())) {
                case PromotionDefinition::class:
                    $this->validatePromotion($command->getPayload(), $violationList);
                    break;

                case PromotionDiscountDefinition::class:
                    $this->validateDiscount($command->getPayload(), $violationList);
                    break;
            }
        }

        if ($violationList->count() > 0) {
            throw new WriteConstraintViolationException($violationList);
        }
    }
public function preValidate ( array $ writeCommands , WriteContext $ context ) : void { $ violationList = new ConstraintViolationList ( ) ; /** @var WriteCommandInterface $command */ foreach ( $ writeCommands as $ command ) { if ( ! $ command instanceof InsertCommand && ! $ command instanceof UpdateCommand ) { continue ; } switch ( get_class ( $ command -> getDefinition ( ) ) ) { case PromotionDefinition :: class : $ this -> validatePromotion ( $ command -> getPayload ( ) , $ violationList ) ; break ; case PromotionDiscountDefinition :: class : $ this -> validateDiscount ( $ command -> getPayload ( ) , $ violationList ) ; break ; } } if ( $ violationList -> count ( ) > 0 ) { throw new WriteConstraintViolationException ( $ violationList ) ; } }
This function validates our incoming delta-values for promotions
and its aggregation. It does only check for business relevant rules and logic.
All primitive "required" constraints are done inside the definition of the entity.

@param array        $writeCommands all incoming commands
@param WriteContext $context       the current writing context

@throws WriteConstraintViolationException
@throws \Exception
This function validates our incoming delta - values for promotions and its aggregation . It does only check for business relevant rules and logic . All primitive required constraints are done inside the definition of the entity .