aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-04-09 15:50:43 -0300
committerSilvio <silvio@devlet.com.br>2010-04-09 15:50:43 -0300
commit4234c6f306ed6f25069e0b5cc6edc40c7dacb564 (patch)
tree4533e3db68c28a06d400a6242fa142f42401acac /classes
parent1996dbfb572285bbba3805fe9073d62a736615c2 (diff)
downloadcinisis-4234c6f306ed6f25069e0b5cc6edc40c7dacb564.tar.gz
cinisis-4234c6f306ed6f25069e0b5cc6edc40c7dacb564.tar.bz2
Initial code for perl backend
Diffstat (limited to 'classes')
-rw-r--r--classes/BiblioIsisDb.php75
-rw-r--r--classes/PhpIsisDb.php4
2 files changed, 71 insertions, 8 deletions
diff --git a/classes/BiblioIsisDb.php b/classes/BiblioIsisDb.php
index 35404bb..3f51945 100644
--- a/classes/BiblioIsisDb.php
+++ b/classes/BiblioIsisDb.php
@@ -11,10 +11,9 @@ class BiblioIsisDb implements IsisDb {
var $fdt;
/**
- * @var $db
- * Database resource.
+ * Class instance of a perl interpreter;
*/
- var $db;
+ var $perl;
/**
* @var $format
@@ -28,17 +27,71 @@ class BiblioIsisDb implements IsisDb {
* @see IsisDb::__construct()
*/
public function __construct($schema) {
+ // Save db schema.
+ $this->format = $schema;
+
+ // Setup $fdt.
+ foreach ($schema['fields'] as $field => $info) {
+ $this->fdt[$field] = $info['name'];
+ }
+
+ // Create a perl instance.
+ $this->perl = new Perl();
+ }
+
+ /**
+ * Send requests to the perl backend.
+ *
+ * @param $method
+ * Backend method name to invoke.
+ *
+ * @param $args
+ * Backend method arguments.
+ *
+ * @return
+ * Backend return value.
+ */
+ function backend($method = 'count', $args = NULL) {
+ // Setup the database.
+ $name = $this->format['db']['name'];
+ $db = CinisisDb::file("$name/$name", 'db');
+
+ // Setup arguments.
+ if ($args != NULL) {
+ $args = '('. $args .')';
+ }
+
+ try {
+ // Call backend.
+ return $this->perl->eval('
+ use Biblio::Isis;
+
+ my $isis = new Biblio::Isis(
+ isisdb => "'. $db .'",
+ );
+
+ return $isis->'. $method . $args .';');
+ }
+ catch (PerlException $exception) {
+ echo __CLASS__ .': Perl error: ' . $exception->getMessage();
+ return FALSE;
+ }
}
/**
* Read an entry.
*
* @see IsisDb::read()
- *
- * @todo
- * Subfields.
*/
public function read($id) {
+ // Database query.
+ $results = $this->backend('to_hash', $id);
+
+ // Tag results.
+ $data = $this->tag($results);
+
+ // Return the result.
+ return $data;
}
/**
@@ -51,6 +104,7 @@ class BiblioIsisDb implements IsisDb {
* @see IsisDb::read()
*/
public function rows() {
+ return $this->backend('count');
}
/**
@@ -84,7 +138,16 @@ class BiblioIsisDb implements IsisDb {
*
* @return
* Tagged database result.
+ *
+ * @todo
+ * Subfields.
*/
function tag($results) {
+ foreach ($results as $key => $value) {
+ $name = $this->format['fields'][$key]['name'];
+ $data[$name] = $value;
+ }
+
+ return $data;
}
}
diff --git a/classes/PhpIsisDb.php b/classes/PhpIsisDb.php
index 9e885d9..136b657 100644
--- a/classes/PhpIsisDb.php
+++ b/classes/PhpIsisDb.php
@@ -25,7 +25,7 @@ class PhpIsisDb implements IsisDb {
// Save db schema.
$this->format = $schema;
- // Setup $fdt used by malete.
+ // Setup $fdt.
foreach ($schema['fields'] as $field => $info) {
$this->fdt[$field] = $info['name'];
}
@@ -105,7 +105,7 @@ class PhpIsisDb implements IsisDb {
function tag($results) {
foreach ($results as $key => $value) {
if ($key != 'mfn') {
- $name = $this->format['fields'][$key]['name'];
+ $name = $this->format['fields'][$key]['name'];
$data[$name] = $value;
}
}