Use addConstraint() in the compound constraint constructor
authorChuck Hagenbuch <chuck@horde.org>
Mon, 28 Sep 2009 18:26:43 +0000 (14:26 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Mon, 28 Sep 2009 18:55:09 +0000 (14:55 -0400)
Collapse compound constraints of the same type

framework/Constraint/lib/Horde/Constraint/Compound.php

index 48d8027..ededf9e 100644 (file)
@@ -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);
 }