From a8017e8ab403dded222fdaeb51047d97c76026c3 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Mon, 28 Sep 2009 14:28:42 -0400 Subject: [PATCH] Revert "add constraint coupler to separate object creation from logic classes" This reverts commit 360abb926cba981e5aa2eba66129a7815004ef1a. --- .../lib/Horde/Constraint/Compound/Factory.php | 21 ---------- .../lib/Horde/Constraint/Compound/Factory/And.php | 17 -------- .../lib/Horde/Constraint/Compound/Factory/Or.php | 17 -------- .../Constraint/lib/Horde/Constraint/Coupler.php | 47 ---------------------- framework/Log/lib/Horde/Log/Filter/Constraint.php | 20 ++------- 5 files changed, 3 insertions(+), 119 deletions(-) delete mode 100644 framework/Constraint/lib/Horde/Constraint/Compound/Factory.php delete mode 100644 framework/Constraint/lib/Horde/Constraint/Compound/Factory/And.php delete mode 100644 framework/Constraint/lib/Horde/Constraint/Compound/Factory/Or.php delete mode 100644 framework/Constraint/lib/Horde/Constraint/Coupler.php diff --git a/framework/Constraint/lib/Horde/Constraint/Compound/Factory.php b/framework/Constraint/lib/Horde/Constraint/Compound/Factory.php deleted file mode 100644 index 359b9fc3d..000000000 --- a/framework/Constraint/lib/Horde/Constraint/Compound/Factory.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ -interface Horde_Constraint_Compound_Factory -{ - /** - * does this factory create objects of the same type as the given object? - * @return boolean True if this factory creates this type of object/ false otherwise - */ - public function createsConstraintType(Horde_Constraint $constraint); - - /** - * create a compound constraint - * - * @return Horde_Constraint_Compound the created constraint - */ - public function create(Horde_Constraint $a, Horde_Constraint $b); -} diff --git a/framework/Constraint/lib/Horde/Constraint/Compound/Factory/And.php b/framework/Constraint/lib/Horde/Constraint/Compound/Factory/And.php deleted file mode 100644 index 3592d8063..000000000 --- a/framework/Constraint/lib/Horde/Constraint/Compound/Factory/And.php +++ /dev/null @@ -1,17 +0,0 @@ - - */ -class Horde_Constraint_Compound_Factory_And implements Horde_Constraint_Compound_Factory -{ - public function create(Horde_Constraint $a, Horde_Constraint $b) - { - return new Horde_Constraint_And($a, $b); - } - public function createsConstraintType(Horde_Constraint $constraint) - { - return $constraint instanceof Horde_Constraint_And; - } -} diff --git a/framework/Constraint/lib/Horde/Constraint/Compound/Factory/Or.php b/framework/Constraint/lib/Horde/Constraint/Compound/Factory/Or.php deleted file mode 100644 index 537f2444e..000000000 --- a/framework/Constraint/lib/Horde/Constraint/Compound/Factory/Or.php +++ /dev/null @@ -1,17 +0,0 @@ - - */ -class Horde_Constraint_Compound_Factory_Or implements Horde_Constraint_Compound_Factory -{ - public function create(Horde_Constraint $a, Horde_Constraint $b) - { - return new Horde_Constraint_Or($a, $b); - } - public function createsConstraintType(Horde_Constraint $constraint) - { - return $constraint instanceof Horde_Constraint_Or; - } -} diff --git a/framework/Constraint/lib/Horde/Constraint/Coupler.php b/framework/Constraint/lib/Horde/Constraint/Coupler.php deleted file mode 100644 index b3e78bdb8..000000000 --- a/framework/Constraint/lib/Horde/Constraint/Coupler.php +++ /dev/null @@ -1,47 +0,0 @@ - - */ -class Horde_Constraint_Coupler -{ - private $_factory; - - public function __construct(Horde_Constraint_Compound_Factory $factory) - { - $this->_factory = $factory; - } - /** - * couple two constraints together - * - * @param Horde_Constraint $husband The first constraint - * @param Horde_Constraint $wife The second constraint - * @return Horde_Constraint_Compound If one of the two arguments is an And constraint, - * then we return that constraint, otherwise, we return a new constraint - */ - public function couple(Horde_Constraint $husband, Horde_Constraint $wife) - { - if($this->_coupleConstraints($husband, $wife)) - { - return $husband; - } - if($this->_coupleConstraints($wife, $husband)) - { - return $wife; - } - return $this->_factory->create($husband, $wife); - } - private function _coupleConstraints(Horde_Constraint $a, Horde_Constraint $b) - { - if($this->_factory->createsConstraintType($a)) - { - $a->addConstraint($b); - return true; - } - return false; - } -} diff --git a/framework/Log/lib/Horde/Log/Filter/Constraint.php b/framework/Log/lib/Horde/Log/Filter/Constraint.php index 95acf8c8c..7a645f0ca 100644 --- a/framework/Log/lib/Horde/Log/Filter/Constraint.php +++ b/framework/Log/lib/Horde/Log/Filter/Constraint.php @@ -22,20 +22,7 @@ */ class Horde_Log_Filter_Constraint implements Horde_Log_Filter_Interface { - protected $_constraints = array(); - protected $_coupler; - - /** - * create a new Constraint based filter - * - * @param Horde_Constraint_Coupler $coupler The default constraint coupler. Use an And coupler - * to make addConstraint create And constraints when a second constraint is added for a field, - * and use and Or coupler to make Or the default coupling of constraints - */ - public function __construct(Horde_Constraint_Coupler $coupler) - { - $this->_coupler = $coupler; - } + private $_constraints = array(); /** * Add a constraint to the filter @@ -47,12 +34,11 @@ class Horde_Log_Filter_Constraint implements Horde_Log_Filter_Interface */ public function addConstraint($field, Horde_Constraint $constraint) { - if(isset($this->_constraints[$field])) { - $this->_constraints[$field] = $this->_coupler->couple($this->_constraints[$field], $constraint); + if ($this->_constraints[$field] instanceof Horde_Constraint) { + $this->_constraints[$field] = new Horde_Constraint_And($this->_constraints[$field], $constraint); } else { $this->_constraints[$field] = $constraint; } - return $this; } -- 2.11.0