Create list queries in the factory.
authorGunnar Wrobel <p@rdus.de>
Mon, 3 Jan 2011 12:46:15 +0000 (13:46 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 4 Jan 2011 07:54:22 +0000 (08:54 +0100)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Factory.php

index 596c00e..67e17ce 100644 (file)
@@ -195,6 +195,33 @@ class Horde_Kolab_Storage_Factory
     }
 
     /**
+     * Create the specified list query type.
+     *
+     * @param string                   $name The query name.
+     * @param Horde_Kolab_Storage_List $list The list that should be queried.
+     *
+     * @return Horde_Kolab_Storage_Query A query handler.
+     *
+     * @throws Horde_Kolab_Storage_Exception In case the requested query is not supported.
+     */
+    public function createListQuery($name, Horde_Kolab_Storage_List $list)
+    {
+        if (class_exists($name)) {
+            $query = new $name($list);
+        } else if (strpos($name, 'Horde_Kolab_Storage_List_Query_') === false) {
+            $query = $this->createListQuery(
+                'Horde_Kolab_Storage_List_Query_' . $name, $list
+            );
+        } else {
+            throw new Horde_Kolab_Storage_Exception(sprintf('No such query "%s"!', $name));
+        }
+        if (method_exists($query, 'setFactory')) {
+            $query->setFactory($this);
+        }
+        return $query;
+    }
+
+    /**
      * Create a namespace handler.
      *
      * @param string $type   The namespace type.