1: <?php
2: /**
3: * Interface for grouped (compound, coupled) constraints.
4: *
5: * @author James Pepin <james@jamespepin.com>
6: */
7: abstract class Horde_Constraint_Coupler implements Horde_Constraint
8: {
9: protected $_constraints = array();
10:
11: public function __construct()
12: {
13: $constraints = func_get_args();
14: foreach ($constraints as $c) {
15: if (! $c instanceof Horde_Constraint) {
16: throw new IllegalArgumentException("$c does not implement Horde_Constraint");
17: }
18: $this->addConstraint($c);
19: }
20: }
21:
22: public function addConstraint(Horde_Constraint $constraint)
23: {
24: $kind = get_class($this);
25: if ($constraint instanceof $kind) {
26: foreach ($constraint->getConstraints() as $c) {
27: $this->addConstraint($c);
28: }
29: } else {
30: $this->_constraints[] = $constraint;
31: }
32: return $this;
33: }
34:
35: public function getConstraints()
36: {
37: return $this->_constraints;
38: }
39: }
40: