Example #1
0
File: NotX.php Project: fieg/csp
 /**
  * @param Constraint $constraint
  * @throws \LogicException
  * @throws \InvalidArgumentException
  */
 public function addConstraint(Constraint $constraint)
 {
     if (0 !== count($this->constraints)) {
         throw new \LogicException('Can only add a single child of type AndX or OrX');
     }
     if (!$constraint instanceof AndX && !$constraint instanceof OrX) {
         throw new \InvalidArgumentException(sprintf('Only constraints of type AndX or OrX allowed, %s given', get_class($constraint)));
     }
     parent::addConstraint($constraint);
 }
Example #2
0
 /**
  * Appends constraints to the compound constraint
  *
  * @param  CompoundConstraint        $constraint
  * @param  array                     $arguments
  * @return CompoundConstraint
  * @throws \InvalidArgumentException
  */
 protected function compound(CompoundConstraint $constraint, $arguments)
 {
     $constraints = array();
     foreach ($arguments as $value) {
         if ($this === $value) {
             $constraints[] = $this->constraint->pop();
         } else {
             throw new \InvalidArgumentException('Invalid argument given, should reuse the ConstraintBuilder');
         }
     }
     $constraints = array_reverse($constraints);
     foreach ($constraints as $c) {
         $constraint->addConstraint($c);
     }
     return $constraint;
 }