From 71d21ff66091523028de50ef6e33838cc170c2be Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Mon, 28 Sep 2009 14:26:43 -0400 Subject: [PATCH] Use addConstraint() in the compound constraint constructor Collapse compound constraints of the same type --- framework/Constraint/lib/Horde/Constraint/Compound.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/framework/Constraint/lib/Horde/Constraint/Compound.php b/framework/Constraint/lib/Horde/Constraint/Compound.php index 48d80274c..ededf9e34 100644 --- a/framework/Constraint/lib/Horde/Constraint/Compound.php +++ b/framework/Constraint/lib/Horde/Constraint/Compound.php @@ -15,15 +15,27 @@ abstract class Horde_Constraint_Compound implements Horde_Constraint if (! $c instanceof Horde_Constraint) { throw new IllegalArgumentException("$c does not implement Horde_Constraint"); } + $this->addConstraint($c); } - $this->_constraints = $constraints; } public function addConstraint(Horde_Constraint $constraint) { - $this->_constraints[] = $constraint; + $kind = get_class($this); + if ($constrainst instanceof $kind) { + foreach ($constrainst->getConstraints() as $c) { + $this->addConstraint($c); + } + } else { + $this->_constraints[] = $constraint; + } return $this; } + public function getConstraints() + { + return $this->_constraints; + } + abstract public function evaluate($value); } -- 2.11.0