Revert "add constraint coupler to separate object creation from logic classes"
authorChuck Hagenbuch <chuck@horde.org>
Mon, 28 Sep 2009 18:28:42 +0000 (14:28 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Mon, 28 Sep 2009 18:55:09 +0000 (14:55 -0400)
This reverts commit 360abb926cba981e5aa2eba66129a7815004ef1a.

framework/Constraint/lib/Horde/Constraint/Compound/Factory.php [deleted file]
framework/Constraint/lib/Horde/Constraint/Compound/Factory/And.php [deleted file]
framework/Constraint/lib/Horde/Constraint/Compound/Factory/Or.php [deleted file]
framework/Constraint/lib/Horde/Constraint/Coupler.php [deleted file]
framework/Log/lib/Horde/Log/Filter/Constraint.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 (file)
index 359b9fc..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?
-/**
- * interface for classes that create compound constraints
- *
- * @author James Pepin <james@jamespepin.com>
- */
-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 (file)
index 3592d80..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?
-/**
- * create And constraints
- *
- * @author James Pepin <james@jamespepin.com>
- */
-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 (file)
index 537f244..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?
-/**
- * create Or constraints
- *
- * @author James Pepin <james@jamespepin.com>
- */
-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 (file)
index b3e78bd..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<?
-/**
- * class for coupling constraints.
- *
- * The primary use for this interface is to allow objects to combine two
- * constraints to form compound constraints
- *
- * @author James Pepin <james@jamespepin.com>
- */
-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;
-    }
-}
index 95acf8c..7a645f0 100644 (file)
  */
 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;
     }