add interfaces for database adapter
authorChristian Weiske <cweiske@cweiske.de>
Mon, 7 May 2012 19:10:51 +0000 (21:10 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 7 May 2012 19:10:51 +0000 (21:10 +0200)
src/phorkie/Database.php
src/phorkie/Database/Adapter/Elasticsearch/Indexer.php
src/phorkie/Database/Adapter/Elasticsearch/Search.php
src/phorkie/Database/Adapter/Elasticsearch/Setup.php
src/phorkie/Database/IIndexer.php [new file with mode: 0644]
src/phorkie/Database/ISearch.php [new file with mode: 0644]
src/phorkie/Database/ISetup.php [new file with mode: 0644]

index 9854e7c7a6085bddf9d019d7d49547493efdccda..786cfe0695ece7bd49b858cabd5ddb53e0e80609 100644 (file)
@@ -3,19 +3,30 @@ namespace phorkie;
 
 class Database
 {
+    public $prefix = '\phorkie\Database_Adapter_Null';
+
+    public function __construct()
+    {
+        if ($GLOBALS['phorkie']['cfg']['elasticsearch'] != '') {
+            $this->prefix = '\phorkie\Database_Adapter_Elasticsearch';
+        }
+    }
     public function getSearch()
     {
-        return new Database_Adapter_Elasticsearch_Search();
+        $class = $this->prefix . '_Search';
+        return new $class();
     }
 
     public function getIndexer()
     {
-        return new Database_Adapter_Elasticsearch_Indexer();
+        $class = $this->prefix . '_Indexer';
+        return new $class();
     }
 
     public function getSetup()
     {
-        return new Database_Adapter_Elasticsearch_Setup();
+        $class = $this->prefix . '_Setup';
+        return new $class();
     }
 }
 
index d9d1032bbeb4bc46989cd88712b4d0d466abcc78..41aa7d71bda77abad0fba12c6de61ab3f5ed487a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace phorkie;
 
-class Database_Adapter_Elasticsearch_Indexer
+class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer
 {
     public function __construct()
     {
index 88ad4ac8f0fb0dd6d73d38fa18ede6018d4f7f6e..d077747b46242b404f176ab8576a6d462526e715 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace phorkie;
 
-class Database_Adapter_Elasticsearch_Search
+class Database_Adapter_Elasticsearch_Search implements Database_ISearch
 {
     public function __construct()
     {
index acbe77c977f5de38c7b64977dc5831ab53cbf91b..066a21c2253f7019959388e40192267709fa7030 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace phorkie;
 
-class Database_Adapter_Elasticsearch_Setup
+class Database_Adapter_Elasticsearch_Setup implements Database_ISetup
 {
     public function __construct()
     {
diff --git a/src/phorkie/Database/IIndexer.php b/src/phorkie/Database/IIndexer.php
new file mode 100644 (file)
index 0000000..61b8a87
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+namespace phorkie;
+
+interface Database_IIndexer
+{
+    public function addRepo(Repository $repo, $crdate = null);
+    public function updateRepo(Repository $repo, $crdate = null);
+    public function deleteAllRepos();
+    public function deleteRepo(Repository $repo);
+}
+
+?>
diff --git a/src/phorkie/Database/ISearch.php b/src/phorkie/Database/ISearch.php
new file mode 100644 (file)
index 0000000..b18d43a
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+namespace phorkie;
+
+interface Database_ISearch
+{
+    public function search($term, $page = 0, $perPage = 10);
+}
+
+?>
diff --git a/src/phorkie/Database/ISetup.php b/src/phorkie/Database/ISetup.php
new file mode 100644 (file)
index 0000000..1ac6b2f
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+namespace phorkie;
+
+interface Database_ISetup
+{
+    public function setup();
+}
+
+?>